SELECT SUM(DECODE(TO_CHAR(mon_date,'D'),1,1)) total_sun
, SUM(DECODE(TO_CHAR(mon_date,'D'),2,1)) total_mon
, SUM(DECODE(TO_CHAR(mon_date,'D'),3,1)) total_tue
, SUM(DECODE(TO_CHAR(mon_date,'D'),4,1)) total_wed
, SUM(DECODE(TO_CHAR(mon_date,'D'),5,1)) total_thus
, SUM(DECODE(TO_CHAR(mon_date,'D'),6,1)) total_fri
, SUM(DECODE(TO_CHAR(mon_date,'D'),7,1)) total_sat
FROM (
SELECT curr_mon + LEVEL - 1 mon_date,
( TRUNC (curr_mon + LEVEL - 1, 'D')
- TRUNC (TRUNC (curr_mon + LEVEL - 1, 'Y'), 'D')
) / 7 + 1 week_no
FROM (SELECT TO_DATE (TO_CHAR(SYSDATE,'YYYYMM'), 'YYYYMM') curr_mon
FROM DUAL)
CONNECT BY curr_mon + LEVEL - 1 <= LAST_DAY (curr_mon));
No comments:
Post a Comment