按凌晨 4 点到凌晨 4 点的值进行分组 SQL Server
我有从 04/01/2012 00:00 到 05/01/2012 05:00 的数据,
假设
StartDate Value
04/01/2012 00:00 10
04/01/2012 05:00 10
04/01/2012 08:00 10
05/01/2012 01:00 10
05/01/2012 04:00 10
05/01/2012 05:00 10
我按日期进行分组,
SUM(Value)...
GROUP BY YEAR(StartDate), MONTH(StartDate),DAY(StartDate)
该组数据从 04/01/2012 00:00 到 05/01/2012 00: 00 并对全天值求和,即 30
,但我需要按不同时间进行分组
,即04/01/2012 04:00 到 05/01/2012 04:00 这样结果将是 40
如何实现这一点。以前有人这样做过...
I have data from 04/01/2012 00:00 to 05/01/2012 05:00
let say
StartDate Value
04/01/2012 00:00 10
04/01/2012 05:00 10
04/01/2012 08:00 10
05/01/2012 01:00 10
05/01/2012 04:00 10
05/01/2012 05:00 10
if I do a group by date
SUM(Value)...
GROUP BY YEAR(StartDate), MONTH(StartDate),DAY(StartDate)
this group data from 04/01/2012 00:00 to 05/01/2012 00:00 and sum the full day value i.e 30
but I need to group by different time
i.e 04/01/2012 04:00 to 05/01/2012 04:00 so that the result will be 40
how to achieve this. Anyone did this before...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
结果:
Result: