SQL Server: Daten Zählen nach Datum gruppiert
Das folgende SQL Transact Code-Beispiel kummuliert die Anzahl aller Datensätze an einem Tag zusammen.
Dabei wird die Anzahl anhand der ID hochgezählt
SELECT COUNT(IDViewLog) AS nViews,
|
Und Ăźber dem Tages-Datum zusammengefasst
GROUP BY CAST(dtView AS date) |
Beispiel
/****** Script for SelectTopNRows command from SSMS ******/ SELECT COUNT(IDViewLog) AS nViews, CAST(dtView AS date) as DateViews FROM tbl_Notes_View_Log GROUP BY CAST(dtView AS date) ORDER BY CAST(dtView AS date) DESC
|
Wichtig ist dabei, dass das eigentliche Datum als Zeitstempel mit Datum Uhrzeit bis zur Millisekunde gespeichert ist
/****** Script for SelectTopNRows command from SSMS ******/ SELECT TOP (1000) [IDViewLog] ,[IDNote] ,[IDUser] ,[dtView] FROM [readdy].[dbo].[tbl_Notes_View_Log]
|
IDViewLog IDNote IDUser dtView 1 0 1 2018-02-26 11:45:50.997 2 0 1 2018-02-26 13:26:13.260 3 0 1 2018-02-26 13:29:44.320 4 0 1 2018-02-26 13:29:49.973 5 0 1 2018-02-26 13:29:50.487 |