Musíte pojmenovat svůj poddotaz:
DECLARE @avg_volume INT
SELECT @avg_volume = ISNULL(AVG(Total_Volume), 0)
FROM ( SELECT station_id ,
DATEPART(Year, date_time) AS YEAR ,
DATEPART(month, date_time) AS MONTH ,
CONVERT(DATE, date_time) AS DATE ,
DATENAME(weekday, date_time) AS weekday ,
SUM(volume) AS Total_volume
FROM rvtcs_data_aggregated_hourly
GROUP BY station_id ,
CONVERT(DATE, date_time) ,
DATEPART(month, date_time) ,
DATEPART(Year, date_time) ,
DATENAME(weekday, date_time)
) AnyNameYouLikeButYouHaveToGiveOne --<-- Here
GROUP BY station_id ,
CONVERT(DATE, date_time) ,
DATEPART(month, date_time) ,
DATEPART(Year, date_time) ,
DATENAME(weekday, date_time)
ORDER BY DATEPART(Year, date_time) ,
DATEPART(month, date_time) ,
CONVERT(DATE, date_time)
SELECT @avg_volume