You really need one CTE here
; With SEASONALITY_AVG_REVENUE(YearKey, Aggregation_Key, Yearly_Avg_Revenue)
AS
(
SELECT ts.YearKey,
agg.Aggregation_Key,
Yearly_Avg_Revenue = AVG(agg.Revenue)
FROM seasonality_custom.TIME_SERIES_INDEX ts INNER JOIN
seasonality_custom.SEASONALITY_AGG_TIME_SERIES agg
ON ts.TIME_SERIES_INDEX = agg.TIME_SERIES_INDEX
GROUP BY ts.YearKey, agg.Aggregation_Key
)
SELECT ts.YearKey,
agg.Aggregation_Key,
agg.Revenue,
Yearly_Avg_Revenue = savg.Yearly_Avg_Revenue
FROM seasonality_custom.TIME_SERIES_INDEX ts
INNER JOIN seasonality_custom.SEASONALITY_AGG_TIME_SERIES agg
ON ts.TIME_SERIES_INDEX = agg.TIME_SERIES_INDEX
INNER JOIN SEASONALITY_AVG_REVENUE savg
ON ts.YearKey = savg.YearKey and agg.Aggregation_Key = savg.Aggregation_Key
Or
As Gordon has mentioned CTE needs to be followed by a SELECT, UPDATE, DELETE statement.
With your current query you can simply select at the end from your second CTE and it will also return the same results but it will be an unnecessary step. Something like this..
;WITH CTE1 (Col1, Col2)
AS
(
-- Some code here
),
CTE2
AS
(
-- Some code here
)
SELECT * FROM CTE2