Add support for complex group by. Still has a bug for order by