aggregation having should apply limit after filtering with group alias sort