Generalizing grouping-type queries