简体   繁体   English

周,月,年至周初的日期

[英]Week, Month, Year number to beginning of week Date

Example: 例:

  • Month Number : 03 月号:03
  • Week Number: 10 周数:10
  • Year : 2018 年:2018

I want this to convert to 3/05/2018 but am unsure how to do this in Tableau/Oracle SQL. 我希望将其转换为3/05/2018,但不确定如何在Tableau / Oracle SQL中执行此操作。 What would be the logic to convert these 3 separate numbers into the beginning of a week? 将这3个独立的数字转换成一周开始的逻辑是什么? The week would start on Monday. 这个星期将从星期一开始。

Thanks 谢谢

The following query should give you the desired result - 以下查询将为您提供所需的结果-

SELECT
    TO_CHAR(START_DATE,'MM/DD/YYYY') AS START_DATE
FROM
(
    SELECT 
        (TRUNC(TO_DATE('2018','YYYY'),'DAY') + 1) + ((LEVEL - 1) * 7) AS START_DATE,
        (TRUNC(TO_DATE('2018','YYYY'),'DAY') + 1) + ((LEVEL - 1) * 7) + 6 AS END_DATE, LEVEL AS WEEK
    FROM 
        DUAL
    CONNECT BY LEVEL <= (((TO_DATE('2018','YYYY') + INTERVAL '1' YEAR) + INTERVAL '-1' DAY) - (TO_DATE('2018','YYYY')))/7
)
WHERE
    WEEK = 10
;

The year 2018 and week number 10 are hardcoded here to get the desired result in this case. 在这种情况下,此处将硬编码2018年和第10周,以获得所需的结果。

Result:- 结果:-

START_DATE 开始日期

03/05/2018 03/05/2018

I think Month Number is not necessary, you can try below code, 我认为月号不是必需的,您可以尝试以下代码,

SELECT NEXT_DAY(TO_DATE((&week_no*7)||' &yyyy', 'DDD YYYY')-7, 2) date_
  FROM dual;

week_no = 10
yyyy = 2018

DATE_   
---------
05-MAR-18

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM