SQL Server GROUP BY datetime ignore hour minute and a select with a date and sum value

后端 未结 5 2112
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 11:54

I have a table with two fields - datetime and int. I want to do a group by on the datetime only on the date ignoring the hour and minute.

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-01 12:23

    SELECT CAST(Datetimefield AS DATE) as DateField, SUM(intfield) as SumField
    FROM MyTable
    GROUP BY CAST(Datetimefield AS DATE)
    

提交回复
热议问题