Oracle按月份累計求和

2021-06-21 13:16:01 字數 1292 閱讀 2653

原表:

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

參考資料:

--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 *** order by ***1,***2 desc) ,在"... from emp;"後面不要加order   by 子句,使用的分析函式的(partition by deptno order by sal)

裡已經有排序的語句了,如果再在句尾新增排序子句,一致倒罷了,不一致,結果就令人費勁了。

oracle中累計求和 oracle累計求和

poj2001 shortest prefixes trie樹應用 沉迷wow又頹了兩天orz,暴雪爸爸要在國服出月卡了.這是要我好好學習嗎?趕緊來刷題了.oj 題目大意是求所有字串裡每乙個字元 硬體相關 jtag介面 jtag joint test action group,聯合測試行動小組 是一...

oracle中累計求和 oracle累計求和

oracle累計求和 將當前行某列的值與前面所有行的此列值相加,即累計求和 方法一 with t as select 1 val from dual union all select 3 from dual union all select 5 from dual union all select ...

按月份統計

id logtimes 12010 03 1213 04 412 2010 04 1313 04 443 2010 05 1813 04 444 2010 06 1813 04 445 2010 07 1813 04 446 2010 05 1813 04 447 2010 05 1813 04 4...