aggregation having should apply limit after filtering