oracle按年月统计

SELECT 
to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'yyyy') 工单单数,
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'01',jh,0))) as 一月,
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'02',jh,0))) as 二月, 
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'03',jh,0))) as 三月,
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'04',jh,0))) as 四月,
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'05',jh,0))) as 五月,
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'06',jh,0))) as 六月,
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'07',jh,0))) as 七月,
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'08',jh,0))) as 八月,
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'09',jh,0))) as 九月,
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'10',jh,0))) as 十月,
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'11',jh,0))) as 十一月,
to_char(SUM(DECODE(to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'MM'),'12',jh,0))) as 十二月,
sum(jh) 小计
from 
 (


select to_char(to_date(C536870974,'yyyy-MM-dd HH:mi:ss'),'yyyymmdd') YYYYMMDD,COUNT(C536870917) jh from t96159 
 group by C536870974
  
 ) e 
 group by to_char(to_date(YYYYMMDD,'yyyy-MM-dd'),'yyyy') 

你可能感兴趣的:(oracle)