- UID
- 7607759
- 阅读权限
- 100
- 帖子
- 9832
- 精华贴数
- 13
- 技术排名
- 99
- 技术积分
- 17008
- 社区排名
- 573
- 社区积分
- 3864
- 注册时间
- 2006-7-17
- 精华贴数
- 13
- 技术积分
- 17008
- 社区积分
- 3864
- 注册时间
- 2006-7-17
- 论坛徽章:
- 259
|
Re: sql实现当月日历
最初由 wngsheng 发布
[B]
select max(su) su,max(mo) mo,max(tu) tu,max(we) we,max(th) th,max(fr) fr,max(sa) sa from
(select case when d=1 then dd end su,
case when d=2 then dd end mo,
case when d=3 then dd end tu,
case when d=4 then dd end we,
case when d=5 then dd end th,
case when d=6 then dd end fr,
case when d=7 then dd end sa,
d,w,iw
from(
select dates,to_char(dates,'dd') dd,to_number(to_char(dates,'d')) d,to_char(dates,'w') w,to_char(dates+1,'iw') iw from
(select trunc(sysdate,'month')+level-1 dates from dual
connect by rownum<last_day(sysdate)-trunc(sysdate,'month')
)
)
)
group by iw
order by iw;
[/COLOR]
环境:oracle 10g [/B]
不错,不过w和iw留1个即可 |
|