oracle 日累计月,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')
按月累計(jì)求和:
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')
--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;
注意:如果沒(méi)有order by 子句,求和就不是“連續(xù)”的
select t.pnum,sum(t.pnum) over(order by t.pnum) leijia,sum(t.pnum) over() zongshu from zh_an t;
使用的分析函數(shù)over (partition by xxx order by xxx1,xxx2 desc) ,在"... from emp;"后面不要加order ? by 子句,使用的分析函數(shù)的(partition by deptno order by sal)
里已經(jīng)有排序的語(yǔ)句了,如果再在句尾添加排序子句,一致倒罷了,不一致,結(jié)果就令人費(fèi)勁了。
與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的oracle 日累计月,Oracle按月份累计求和的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php中的getdate 函数,PHP
- 下一篇: oracle怎么查询表空间信息,查询Or