通过SQL查询日期

select *
  from (select ceil((to_char(everyday, 'dd') +
                    (to_char(to_date('20160101', 'yyyymmdd'), 'd') - 1)) / 7) as week,
               sum(decode(to_char(everyday, 'D'),
                          '1',
                          to_char(everyday, 'dd'))) as "Sunday",
               sum(decode(to_char(everyday, 'D'),
                          '2',
                          to_char(everyday, 'dd'))) as "Monday",
               sum(decode(to_char(everyday, 'D'),
                          '3',
                          to_char(everyday, 'dd'))) as "Tuesday",
               sum(decode(to_char(everyday, 'D'),
                          '4',
                          to_char(everyday, 'dd'))) as "Wednesday",
               sum(decode(to_char(everyday, 'D'),
                          '5',
                          to_char(everyday, 'dd'))) as "Thusday",
               sum(decode(to_char(everyday, 'D'),
                          '6',
                          to_char(everyday, 'dd'))) as "Friday",
               sum(decode(to_char(everyday, 'D'),
                          '7',
                          to_char(everyday, 'dd'))) as "Saturday"
          from (select to_date('20160101', 'yyyymmdd') + level - 1 as everyDay
                  from dual
                connect by level <= (last_day(to_date('20160101', 'yyyymmdd')) -
                           to_date('20160101', 'yyyymmdd') + 1))
         group by ceil((to_char(everyday, 'dd') +
                       (to_char(to_date('20160101', 'yyyymmdd'), 'd') - 1)) / 7))
 order by week


你可能感兴趣的:(通过SQL查询日期)