convert joins, group by, having and order by to seq