原表:
select to_char(reg_Date,'yyyy-mm') regDate, count(*) count from Ep_Info t where 1=1 and t.reg_Date>=to_date('2013-02','yyyy-mm') and t.reg_Date<=to_date('2014-05','yyyy-mm') group by to_char(reg_Date,'yyyy-mm') order by to_char(reg_Date,'yyyy-mm')
按月累计求和:
select to_char(reg_Date,'yyyy-mm') regDate2,sum(count(*)) over(order by to_char(reg_Date,'yyyymm'), count(*)) from Ep_Info t where 1=1 and t.reg_Date>=to_date('2011-12','yyyy-mm') and t.reg_Date<=to_date('2014-04','yyyy-mm') group by to_char(reg_Date,'yyyy-mm'),to_char(reg_Date,'yyyymm')
本文介绍了SQL中如何通过GROUP BY和ORDER BY子句结合使用来实现按月累计求和及连续求和的操作,提供了具体的查询语句示例和注意事项。


846





