参考:

http://www.cnblogs.com/lanzi/archive/2010/10/26/1861338.html

select * from bitest.tmp_0222_zym ;

ID    DATE_V    VALUE_V
1    20160101    1
1    20160102    2
1    20160104    4
2    20160101    1
2    20160102    2
2    20160104    4
2    20170104    4

只取日期之前3天的来求和

select id,date_v,value_v,sum(value_v)over(order by to_number(id||date_v) range between 3 preceding and 0 following) mm  
from bitest.tmp_0222_zym  t order by id asc,date_v asc

ID    DATE_V    VALUE_V    MM
1    20160101    1    1
1    20160102    2    3
1    20160104    4    7
2    20160101    1    1
2    20160102    2    3
2    20160104    4    7
2    20170104    4    4

问题1:如果不写id||date_v,那么mm会翻倍,但是这样写的话会有歧义
问题2:如果跨月怎样处理

 

posted on 2017-02-22 16:29  洛丹伦的雪  阅读(216)  评论(0编辑  收藏  举报