我有这种情况,其中必须汇总属于特定日期范围(每 7 天)的每个项目的采购订单。
ITEM_NUMBER ORDERED_DATE ORDER_QUANTITY
1 06/01/2013 5
1 06/02/2013 12
1 06/03/2013 3
1 06/06/2013 8
1 06/18/2013 7
1 06/21/2013 9
1 06/29/2013 3
1 06/30/2013 4
2 06/03/2013 24
2 06/07/2013 1
2 06/19/2013 22
2 06/23/2013 12
2 06/30/2013 9
上述记录必须汇总到关于 ITEM 的 7 天窗口中,如下所示
Item 1 - Orders from 06/01/2013 to 06/07/2013 as one group (7 days)
Item 1 - Orders from 06/18/2013 to 06/24/2013 as second group (7 days)
Item 1 - Orders from 06/29/2013 to 07/05/2013 as third group (7 days)
Item 2 - Orders from 06/03/2013 to 07/09/2013 as forth group (7 days) and so on
因此最终输出应该是
ITEM_NUMBER MIN(ORDERED_DATE) SUM(ORDER_QUANTITY)
1 06/01/2013 28
1 06/18/2013 16
1 06/29/2013 7
2 06/03/2013 25
2 06/19/2013 34
2 06/30/2013 9
如果这是重复,请道歉。提前致谢!