GROUP BY support for buildQuery method