상세 컨텐츠

본문 제목

달력만들기

DataBase/Oracle

by 탑~! 2014. 4. 1. 15:37

본문

select sum(decode(a.day_num, '1', a.day_cnt, '')) sun_day,

       sum(decode(a.day_num, '2', a.day_cnt, '')) mon_day,

       sum(decode(a.day_num, '3', a.day_cnt, '')) tue_day,

       sum(decode(a.day_num, '4', a.day_cnt, '')) wed_day,

       sum(decode(a.day_num, '5', a.day_cnt, '')) thu_day,

       sum(decode(a.day_num, '6', a.day_cnt, '')) fri_day,

       sum(decode(a.day_num, '7', a.day_cnt, '')) sat_day

  from (select (rownum + 7) - to_number(to_char(to_date('200912'||to_char(rownum), 'yyyymmdd'), 'd')) day_cal,

               to_char(to_date('200912'||to_char(rownum), 'yyyymmdd'), 'd') day_num,

               rownum day_cnt

          from all_objects  

         where rownum <= to_number(to_char(last_day(to_date('200912'||'01', 'yyyymmdd')),'dd'))

        ) a

 group by a.day_cal

관련글 더보기