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

后端 未结 5 2109
没有蜡笔的小新
没有蜡笔的小新 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:20

    As he didn't specify which version of SQL server he uses (date type isn't available in 2005), one could also use

    SELECT CONVERT(VARCHAR(10),date_column,112),SUM(num_col) AS summed
    FROM table_name
    GROUP BY CONVERT(VARCHAR(10),date_column,112)
    

提交回复
热议问题