with x0 as
(select to_date('2015-01-01','yyyy-mm-dd') as 年初 from dual),
x1 as
(select 年初,add_months(年初,12) as 下年年 from x0),
x2 as
(select 年初,下年初,下年初-年初 as 天数 from x1),
x3 as/*生成列表*/
(select 年初+(level-1) as 日期 from x2 connect by level<天数),
x4 as/*对数据进行转换*/
(select 日期,to_char(日期,'DY') as 星期 from x3)
/*汇总天数*/
select 星期,count(*) as 天数 from x4 group by 星期;
步骤分解:
1.取得当年年度信息
2.计算一年有多少天
3.生成日期列表
4.转换为对应的星期标识
5.汇总