您可以使用DATEPART()
and CONVERT()
,我假设 CallBegin 不存储为日期时间:
SELECT YEAR(CONVERT(DATETIME,CallBegin,103))'Year'
, DATEPART(quarter,CONVERT(DATETIME,CallBegin,103))'Quarter'
, DATEPART(hour,CONVERT(DATETIME,CallBegin,103))'Hour'
, COUNT(*)
FROM Calls
GROUP BY YEAR(CONVERT(DATETIME,CallBegin,103))
, DATEPART(quarter,CONVERT(DATETIME,CallBegin,103))
, DATEPART(hour,CONVERT(DATETIME,CallBegin,103))
如果您想跨越年份,只需消除年份部分:
SELECT DATEPART(quarter,CONVERT(DATETIME,CallBegin,103))'Quarter'
, DATEPART(hour,CONVERT(DATETIME,CallBegin,103))'Hour'
, COUNT(*)
FROM Calls
GROUP BY DATEPART(quarter,CONVERT(DATETIME,CallBegin,103))
, DATEPART(hour,CONVERT(DATETIME,CallBegin,103))