fixed aggregation query