There are examples for this with a Date column, but I have a Datetime column.
How do you count number of rows created per day with a datetime column?
Example Data:
ID CreatedDatetime
1 2017-05-21 09:14:41.022 -05:00
2 2017-05-21 07:16:49.026 -05:00
3 2017-05-23 08:18:46.023 -05:00
Example Output of the needed query:
Date RowsCreatedOnDate
2017-05-21 2
2017-05-23 1
CodePudding user response:
SELECT cast(CreatedDatetime as Date) as [Date], count(*) As RowsCreatedOnDate
FROM [MyTable]
GROUP BY cast(CreatedDatetime as Date)
See it work here:
https://dbfiddle.uk/?rdbms=sqlserver_2019&fiddle=d6caf210d264cc1b47e3da0cb804589a