Good job! There is also an alternative CTE syntax that looks like this:
WITH OrderTotalPrices (OrderID, TotalPrice) AS (
SUM(UnitPrice * Quantity)
FROM Orders O
JOIN OrderItems OI
ON O.OrderID = OI.OrderID
GROUP BY O.OrderID
AVG(TotalPrice) AS AvgTotalPrice
This time, we provided the column names right after the CTE's name, inside a pair of parentheses (
WITH OrderTotalPrices (OrderID, TotalPrice) AS ...). This way, we didn't have to use the
AS keyword to name the columns inside the CTE.
This syntax is completely optional. It's up to you whether you want to use it and it depends on your personal preferences.