我每15分钟收集一大堆数据。我试图在某个时间段之间选择数据,然后在该时间段内将其除以另一个日期间隔。并且在这些间隔内总和超过一定时间段。
例如,我希望能够在01/01/2009和01/01/2010之间选择数据,并按日期范围分类01/01/2009 - 05/01 / 2009,05 / 02/2009 - 11/01/2009,11 / 02/2009 - 01/01/2010然后在每个组中选择时间00:00:01 - 12:00:00和12:00:01 - 23:59:59的数据
SELECT SUM(Data.usage)AS sum
FROM Data.meter_id = Meter.id
WHERE Data.start_read >= '2009-01-01'
AND Data.end_read <= '2010-01-01 23:59:59'
GROUP BY日期范围?不确定如何分离数据。感谢
答案 0 :(得分:2)
要按日期范围分组,我经常使用案例陈述:
Group By Case
When start_read between '01/01/2009' and '05/01/2010' then 'Jan-Apr 09'
When start_read between '05/01/2009' and '11/01/2010' then 'May-Nov 09'
...etc