merge group by clauses as well

like rails 3