इस बारे में कैसा है? SQL सर्वर 2008 मानते हुए:
SELECT CAST(StartDate as date) AS ForDate,
DATEPART(hour,StartDate) AS OnHour,
COUNT(*) AS Totals
FROM #Events
GROUP BY CAST(StartDate as date),
DATEPART(hour,StartDate)
2008 से पहले के लिए:
SELECT DATEADD(day,datediff(day,0,StartDate),0) AS ForDate,
DATEPART(hour,StartDate) AS OnHour,
COUNT(*) AS Totals
FROM #Events
GROUP BY CAST(StartDate as date),
DATEPART(hour,StartDate)
इसका परिणाम है:
ForDate | OnHour | Totals
-----------------------------------------
2011-08-09 00:00:00.000 12 3