Oracle按月份累计求和

原表:


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') 



参考资料: http://oracle.chinaitlab.com/exploiture/897193.html

--zhongan soft stone
create table zh_an(pnum number(4));
insert into zh_an values(1);
insert into zh_an values(2);
insert into zh_an values(3);
insert into zh_an values(4);
select * from zh_an;

select t.pnum,sum(t.pnum) over(order by t.pnum) leijia from zh_an t;
注意:如果没有order by 子句,求和就不是“连续”的

select t.pnum,sum(t.pnum) over(order by t.pnum) leijia,sum(t.pnum) over() zongshu from zh_an t;

使用的分析函数over (partition by xxx order by xxx1,xxx2 desc) ,在"... from emp;"后面不要加order   by 子句,使用的分析函数的(partition by deptno order by sal)
里已经有排序的语句了,如果再在句尾添加排序子句,一致倒罢了,不一致,结果就令人费劲了。

你可能感兴趣的:(Oracle)