用sql语句得到指定日期所在的周是本年度第几周(Specify the date where the annual week was the first few weeks with the SQL statement).doc
- 1、本文档共7页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
用sql语句得到指定日期所在的周是本年度第几周(Specify the date where the annual week was the first few weeks with the SQL statement)
用sql语句得到指定日期所在的周是本年度第几周(Specify the date where the annual week was the first few weeks with the SQL statement)
Specify the date where the annual week was the first few weeks with the SQL statement
Personal classification: SQL skills
Yesterday, a customer demand, demand has to be used for the specified date in the week was the year of the first few weeks
Seeing this question, I naturally think of the use of to_char (D,ww):
SQL, select, date2010-01-1+ rownum - 1 r,
2 to_char (date2010-01-1+ rownum - 1,d) -1 wn,
3 to_number (to_char (date2010-01-1+ rownum - 1,ww)) nthweek
4 from dual
5 connect by rownum = date2010-01-27- date2010-01-1 + 1
6 /
R WN NTHWEEK
Am
2010-1-1 51
2010-1-2 61
2010-1-3 01
2010-1-4 11
2010-1-5 21
2010-1-6 31
2010-1-7 41
2010-1-8 52
2010-1-9 62
2010-1-10 02
2010-1-11 12
2010-1-12 22
2010-1-13 32
2010-1-14 42
2010-1-15 53
2010-1-16 63
2010-1-17 03
2010-1-18 13
2010-1-19 23
2010-1-20 33
2010-1-21 43
2010-1-22 54
2010-1-23 64
2010-1-24 04
2010-1-25 14
2010-1-26 24
2010-1-27 34
27 rows selected
From the above data, the first group is the true color corresponding to the first week, but this function is the first 7 days as the first week, the first week of the first week with the actual difference of 4 days to four days, this led directly behind the data is not accurate. Seemingly online also did not find a direct solution to this problem Oracle system function, no way, had to write a SQL:
SQL with, TMP, as (select, date2010-01-27, D, from, dual)
2, select, R, wn,
3 sum (decode (WN, 1, 1, 0)) over (order, by, rownum) +
4 decode (to_char (TRUNC (D,y) - 1,d), 1,1,1) nthweek
5 from (select, TRUNC (D,y) + rownum - 1, R, d,
6 to_char (TRUNC (D,y) + rownum - 1,d) - 1 WN
7 from TMP
8 connect by - TRUNC rownum = D (D,y) + 1)
9 /
R WN NTHWEEK
Am
2010-1-1 51
2010-1-2 61
2010-1-3 01
2010-1-4 12
2010-1-5 22
2010-1-6 32
2010-1-7 42
2010-1-8 5 2
2010-1-9 6 2
2010-1-10 0 2
2010-1-11 1 3
2010-1-12 2 3
2010-1-13 3 3
2010-1-14 4 3
2010-1-15 5 3
2010-1-16 6 3
3什么0
2010-1-
您可能关注的文档
- 玻璃器具等的清洗、烘干、包扎、灭菌实验(Cleaning, drying, bandaging and sterilizing experiments of glassware).doc
- 玻璃分类(Glass classification).doc
- 现货盘面知识(Spot disk knowledge).doc
- 玻璃幕墙的施工方案及施工工艺(Construction scheme and construction technology of glass curtain wall).doc
- 玻璃材质(Glass material).doc
- 玻璃纤维桩修复残根残冠的临床观察(Clinical observation of glass fiber post for restoration of residual roots and crowns).doc
- 玻璃清洗(Glass cleaning).doc
- 珍珠奶茶制作方法(Method for making pearl milk tea).doc
- 玻璃检测(Glass inspection).doc
- 玻璃纤维增强型复合树脂桩核修复基牙折断烤瓷牙效果观察(Effect of glass fiber reinforced composite resin post core for restoration of abutment fracture of porcelain fused to tooth).doc
- 《JJF 2132-2024荧光紫外灯人工气候老化试验装置校准规范:辐射照度参数》.pdf
- JJF 2120-2024轮速传感器校准规范.pdf
- 计量规程规范 JJF 2120-2024轮速传感器校准规范.pdf
- 《JJF 2129-2024钙钛矿太阳电池校准规范:光电性能参数》.pdf
- JJF 2129-2024钙钛矿太阳电池校准规范:光电性能参数.pdf
- 《JJF 2120-2024轮速传感器校准规范》.pdf
- JJF 2117-2024沥青混合料理论最大相对密度仪校准规范.pdf
- JJF 2116-2024特定蛋白分析仪校准规范.pdf
- 《JJF 2116-2024特定蛋白分析仪校准规范》.pdf
- 计量规程规范 JJF 2117-2024沥青混合料理论最大相对密度仪校准规范.pdf
最近下载
- 职业暴露应急预案演练记录.docx
- 2024年湖南省中考化学试题(附答案解析).docx
- 销售人员必备河北省石家庄市平山县医疗机构分布明细.doc VIP
- 征信简版电子版PDF个人信用报告最新版2024年可编辑带水印模板.pdf
- 2023年教师资格(高级中学)-化学知识与教学能力(高中)考试历年真题难题荟萃带答案1.docx VIP
- 2023年教师资格(高级中学)-化学知识与教学能力(高中)考试历年主人难题荟萃带答案.docx VIP
- 《提高一级护理病人床边交接班合格率_品管圈》.ppt
- 利用Python进行数据可视化的步骤.pdf VIP
- 电影配音---小学英语口语教学新模式.pdf
- 联合厂房围护系统项目—彩钢板围护等工程施工组织设计(围护结构).doc
文档评论(0)