ITPUB论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
更多
查看: 3381|回复: 14

sql实现当月日历 [复制链接]

注册会员

中级会员

精华贴数
0
技术积分
520
社区积分
1877
注册时间
2001-12-6
论坛徽章:
16
2008新春纪念徽章
日期:2008-02-13 12:43:03迷宫蛋
日期:2011-12-11 15:53:26ITPUB十周年纪念徽章
日期:2011-11-01 16:19:41紫蛋头
日期:2011-08-02 08:31:192011新春纪念徽章
日期:2011-02-18 11:43:332010广州亚运会纪念徽章:帆船
日期:2010-12-01 11:34:20ITPUB9周年纪念徽章
日期:2010-10-08 09:28:512010新春纪念徽章
日期:2010-03-01 11:19:49祖国60周年纪念徽章
日期:2009-10-09 08:28:00ITPUB8周年纪念徽章
日期:2009-09-27 10:21:21生肖徽章2007版:狗
日期:2009-09-15 08:24:52生肖徽章2007版:羊
日期:2009-02-25 15:07:52
发表于 2007-7-9 16:53:40 |显示全部楼层

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

版主

无名扫把

精华贴数
13
技术积分
17008
社区积分
3864
注册时间
2006-7-17
论坛徽章:
259
ITPUB十周年纪念徽章
日期:2011-11-01 16:21:152010广州亚运会纪念徽章:保龄球
日期:2011-04-06 21:11:192011新春纪念徽章
日期:2011-01-25 15:41:012010广州亚运会纪念徽章:现代五项
日期:2010-11-12 16:48:49ITPUB9周年纪念徽章
日期:2010-10-08 09:31:21ITPUB技术丛书作者
日期:2010-09-26 15:08:592010系统架构师大会纪念
日期:2010-09-03 16:39:57嫦娥
日期:2010-08-13 08:18:21ITPUB年度最佳BLOG写作奖
日期:2010-06-12 13:16:47ITPUB伯乐
日期:2010-05-17 15:54:472010数据库技术大会纪念徽章
日期:2010-05-13 10:04:27祖母绿
日期:2010-05-12 16:00:02
发表于 2007-7-9 17:02:18 |显示全部楼层

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个即可

使用道具 举报

注册会员

高级会员

精华贴数
1
技术积分
10851
社区积分
52
注册时间
2006-7-30
论坛徽章:
24
生肖徽章:狗
日期:2006-09-07 10:14:43数据库板块每日发贴之星
日期:2008-07-26 01:02:20生肖徽章2007版:兔
日期:2008-10-13 11:10:112008北京奥运纪念徽章:铁人三项
日期:2008-10-24 13:27:21开发板块每日发贴之星
日期:2008-12-27 01:01:09生肖徽章2007版:马
日期:2009-11-18 10:45:032010新春纪念徽章
日期:2010-03-01 11:21:02ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51ERP板块每日发贴之星
日期:2011-05-18 01:01:012012新春纪念徽章
日期:2012-01-04 11:51:22数据库板块每日发贴之星
日期:2008-02-29 01:04:112008新春纪念徽章
日期:2008-02-13 12:43:03
发表于 2007-7-9 17:03:16 |显示全部楼层
不错,不过都有查出一年的了!

使用道具 举报

版主

JJ娃 尿娃 水娃

精华贴数
2
技术积分
6749
社区积分
9362
注册时间
2006-12-17
论坛徽章:
104
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44授权会员
日期:2007-10-20 11:50:242012新春纪念徽章
日期:2012-01-04 11:53:29现任管理团队成员
日期:2011-05-07 01:45:08ITPUB十周年纪念徽章
日期:2011-11-01 16:23:26
发表于 2007-7-9 21:57:12 |显示全部楼层

使用道具 举报

注册会员

探险者

精华贴数
0
技术积分
404
社区积分
228
注册时间
2006-11-10
论坛徽章:
1
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44
发表于 2007-7-12 15:46:40 |显示全部楼层

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]


代码格式缩进一下,看看清楚都好啊

使用道具 举报

注册会员

因为专注,所以专业

精华贴数
1
技术积分
2487
社区积分
5
注册时间
2004-10-5
论坛徽章:
10
授权会员
日期:2007-07-18 11:34:32ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44生肖徽章2007版:鸡
日期:2008-12-02 12:45:45生肖徽章2007版:龙
日期:2008-12-07 18:27:322009新春纪念徽章
日期:2009-01-04 14:52:28生肖徽章2007版:猪
日期:2009-02-18 12:56:472009日食纪念
日期:2009-07-22 09:30:00
发表于 2007-7-12 17:27:51 |显示全部楼层
非常好。以前也想写,没写出来。

稍微纠正一下。 最后那个要 + 1
LAST_DAY (SYSDATE)- TRUNC (SYSDATE, 'month') + 1

使用道具 举报

注册会员

Just do it!

精华贴数
0
技术积分
3117
社区积分
143
注册时间
2005-5-6
论坛徽章:
99
红孩儿
日期:2007-06-17 01:39:23生肖徽章2007版:牛
日期:2008-01-02 17:35:53IT宝贝
日期:2009-09-21 09:51:33
发表于 2007-7-12 17:33:54 |显示全部楼层
9i下也适用..

使用道具 举报

注册会员

一般会员

精华贴数
0
技术积分
266
社区积分
0
注册时间
2006-5-22
论坛徽章:
0
发表于 2007-7-12 17:36:29 |显示全部楼层
创意不错,楼主真牛。

使用道具 举报

精华贴数
9
技术积分
27549
社区积分
35987
注册时间
2006-11-29
论坛徽章:
28
现任管理团队成员
日期:2011-05-07 01:45:082012新春纪念徽章
日期:2012-01-04 11:53:29复活蛋
日期:2011-06-05 19:14:17蛋疼蛋
日期:2011-11-22 11:02:04迷宫蛋
日期:2011-11-03 20:45:28灰彻蛋
日期:2011-12-23 12:28:48紫蛋头
日期:2011-05-27 03:15:47鲜花蛋
日期:2011-06-14 12:21:24茶鸡蛋
日期:2011-07-04 13:00:35咸鸭蛋
日期:2011-06-12 08:53:51蜘蛛蛋
日期:2011-07-29 11:41:18双黄蛋
日期:2011-10-20 14:03:57
发表于 2007-7-12 17:58:39 |显示全部楼层
牛尹~~~~

使用道具 举报

注册会员

初级会员

精华贴数
0
技术积分
4
社区积分
0
注册时间
2004-10-21
论坛徽章:
0
发表于 2007-7-12 18:14:33 |显示全部楼层

2007年8月 9月显示问题

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
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')+1
)
)
)
group by w
order by w;

//8月
SU MO TU WE TH FR SA
-- -- -- -- -- -- --
05 06 07 01 02 03 04
12 13 14 08 09 10 11
19 20 21 15 16 17 18
26 27 28 22 23 24 25
          29 30 31

//9月

SU MO TU WE TH FR SA
-- -- -- -- -- -- --
02 03 04 05 06 07 01
09 10 11 12 13 14 08
16 17 18 19 20 21 15
23 24 25 26 27 28 22
30                          29

使用道具 举报

相关内容推荐
您需要登录后才可以回帖 登录 | 注册

TOP技术积分榜 社区积分榜 徽章 电子杂志 团队 统计 邮箱 虎吧 老博客 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档 | IT博客
CopyRight 1999-2011 itpub.net All Right Reserved. 北京皓辰网域网络信息技术有限公司版权所有 联系我们 网站律师 隐私政策 知识产权声明
京ICP证:060528号 北京市公安局海淀分局网监中心备案编号:1101082001 广播电视节目制作经营许可证:编号(京)字第1149号
  
回顶部