分隔月份之间的周数

huangapple go评论65阅读模式
英文:

SPLIT Week between months

问题

要求是将周分割成月份,即将TECHNICAL_WEEK分割成不同的部分。将技术周的开始日期设为星期一,但如果月份在同一周内,则将月份的第一天设为开始日期,并将该周的其余日期设为月份的第一天。下一周的开始日期应为星期一。

请帮助构建一个HANA SQL查询。
示例结果如下:

DAY          -------        TECH_WEEK  
20230529     -------        20230529  
20230530     -------        20230529  
20230531     -------        20230529  
20230601     -------        20230601    
20230602     -------        20230601  
20230603     -------        20230601    
20230604     -------        20230601    
英文:

Requirement is to split weeks between Months i.e. TECHNICAL_WEEK. populate tech week as Monday date but If month within the same week then populate 1st day of month and remaining days in week with e the 1st day of month. the Next week should be populated as Monday date.

Please help to build a HANA SQL
Example result below

DAY          -------        TECH_WEEK  
20230529     -------        20230529  
20230530     -------        20230529  
20230531     -------        20230529  
20230601     -------        20230601    
20230602     -------        20230601  
20230603     -------        20230601    
20230604     -------        20230601    

答案1

得分: 2

以下是翻译好的部分:

让我们来看一些示例数据:

SELECT GENERATED_PERIOD_START DAY
FROM SERIES_GENERATE_DATE('INTERVAL 1 DAY', '2023-01-01', '2024-01-01')

根据我对您需求的理解,以下语句应该可以完成任务:

SELECT 
    DAY, add_days(DAY, -1 * CASE WHEN dayofmonth(day) - 1 < weekday(day) THEN dayofmonth(day) - 1 ELSE weekday(day) END) TECH_WEEK
FROM
(
    SELECT GENERATED_PERIOD_START DAY
    FROM SERIES_GENERATE_DATE('INTERVAL 1 DAY', '2023-01-01', '2024-01-01')
)
英文:

Let's take some example data:

SELECT GENERATED_PERIOD_START DAY
FROM SERIES_GENERATE_DATE(&#39;INTERVAL 1 DAY&#39;, &#39;2023-01-01&#39;, &#39;2024-01-01&#39;)

As per my understanding of your requirement, this statement should do the job:

SELECT 
	DAY, add_days(DAY, -1 * CASE WHEN dayofmonth(day) - 1 &lt; weekday(day) THEN dayofmonth(day) - 1 ELSE weekday(day) END) TECH_WEEK
FROM
(
	SELECT GENERATED_PERIOD_START DAY
	FROM SERIES_GENERATE_DATE(&#39;INTERVAL 1 DAY&#39;, &#39;2023-01-01&#39;, &#39;2024-01-01&#39;)
)

huangapple
  • 本文由 发表于 2023年6月12日 01:46:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76451735.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定