Fix for queries with groupBy