我試圖按時間間隔(小時)對結果進行分組,我無法爲我的生活弄清楚這一點。我需要專家來幫助我,任何人都可以看到我要出錯的地方嗎?不按時間間隔分組SQL Server
DECLARE @IntervalMinutes AS INT
SELECT @IntervalMinutes = 60
SELECT
CONVERT(VARCHAR(5),DATEADD(MINUTE,(DATEDIFF(MINUTE,'19000101',dbo.cmp_EEAddLines.CallTime)/@IntervalMinutes) * @IntervalMinutes, '19000101'),108) AS CallTime,
COUNT(dbo.Dial.HistoryID) AS TotalDials,
SUM(CONVERT(numeric, dbo.CRCTotal.Contact)) AS Contacts,
SUM(CONVERT(numeric, dbo.CRCTotal.FinalCRC)) AS Completes
FROM
dbo.cmp_EEAddLines LEFT OUTER JOIN
dbo.Dial ON
dbo.cmp_EEAddLines.DialID = dbo.Dial.DialID LEFT OUTER JOIN
dbo.CRCTotal ON
dbo.Dial.CRC = dbo.CRCTotal.CRC
WHERE
(dbo.cmp_EEAddLines.CallDate >= 29/03/2015)
GROUP BY
CallTime