6.11 Use group’s aggregation value when filtering6.11 Use group’s aggregation value when filtering
We have an aggregation table for the sales of grouped products:
Now we want to find out the product whose sales is greater than the average in its group:
To solve this problem, we can first calculate group’s average sales and assign it to the temporary variable a, and then use ProductSales>a as the filter condition to filter the group. Since it is a two-step calculation, an extra layer of parentheses is required.