Q&A about the site for professional and enthusiast programmers
SELECT CAST(DATEPART(weekday, BaseComments.[Date]) AS nvarchar(MAX)) + ' - ' + DATENAME(weekday, BaseComments.[Date]) + ' / ' + CAST(BaseComments.[Hour] AS nvarchar(MAX)) + ':00 - ' + CAST(BaseComments.[Hour] AS nvarchar(MAX)) + ':59' AS Timeframe, AVG(BaseComments.[Comment_Count]) AS [Average # of comments] FROM ( SELECT COUNT(*) AS Comment_Count, CAST(CreationDate AS Date) AS Date, DATEPART(hour, CreationDate) AS Hour FROM Comments GROUP BY CAST(CreationDate AS Date), DATEPART(hour, CreationDate) ) AS BaseComments GROUP BY CAST(DATEPART(weekday, BaseComments.[Date]) AS nvarchar(MAX)) + ' - ' + DATENAME(weekday, BaseComments.[Date]) + ' / ' + CAST(BaseComments.[Hour] AS nvarchar(MAX)) + ':00 - ' + CAST(BaseComments.[Hour] AS nvarchar(MAX)) + ':59' ORDER BY CAST(DATEPART(weekday, BaseComments.[Date]) AS nvarchar(MAX)) + ' - ' + DATENAME(weekday, BaseComments.[Date]) + ' / ' + CAST(BaseComments.[Hour] AS nvarchar(MAX)) + ':00 - ' + CAST(BaseComments.[Hour] AS nvarchar(MAX)) + ':59'