Fix group_by ordering problem.
At the expense of even more complicated SQL. Closes #115