Evaluation Order and Common Problems
Window functions and GROUP BY
11. What Window Functions See - Part 2
Summary and Review


As you can see, the query failed. However, let's take a look at another modification of this example:

  MAX(FinalPrice) AS MaxFinal,
  AVG(MAX(FinalPrice)) OVER() AS AvgMaxFinalPrice
FROM Auction
GROUP BY CategoryId;

What will happen now?


Run the template.

This query succeeded because we used an aggregate function (MAX(FinalPrice)) that was indeed available after grouping the rows. By the way, this is the only place where you can nest aggregate functions inside one another.