SQL Server GROUP BY datetime忽略小时分钟,并选择一个日期和总和值 [英] SQL Server GROUP BY datetime ignore hour minute and a select with a date and sum value
本文介绍了SQL Server GROUP BY datetime忽略小时分钟,并选择一个日期和总和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个两个字段的表 - datetime
和 int
。我只想在忽略小时和分钟的日期在 datetime
上进行一个组。 SELECT
语句应该返回映射到一天内的int的总和的日期。
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. The SELECT
statement should return a date that maps to the sum of the int of a single day.
推荐答案
SELECT CAST(Datetimefield AS DATE) as DateField, SUM(intfield) as SumField
FROM MyTable
GROUP BY CAST(Datetimefield AS DATE)
这篇关于SQL Server GROUP BY datetime忽略小时分钟,并选择一个日期和总和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文