Reversed min, max ordering.
FEATURE: Handle null keys group.

The problem is that ES does not return value when the group keys are nulls:

select c1, c2, count(a1), max(a2) where w group by c1, c2 having h

The solution is to change this into a union of

select c1, c2, count(a1), max(a2) where w group by c1, c2 having h
select count(a1), max(a2) where w and c1 is null and c2 is null having h

Reviewed-by: robert.macomber@socrata.com