【问题标题】:How to calculate the last week of every month?如何计算每个月的最后一周?
【发布时间】:2021-04-15 18:31:15
【问题描述】:

我一直在环顾四周,但似乎找不到任何可以回答这个问题的东西。我想计算每个月最后一周的日期。例如,2021 年 4 月最后一周的日期是 26-04-2021。我想要一个日期,而不是周数。

我使用 Google Big Query,我确实有一个日历表可以用来提取年份和月份。

谢谢, 艾米丽

【问题讨论】:

  • 你有每个月的日期列表吗?我不熟悉 Google Big Query,但您正在寻找的算法可能是 this question

标签: date google-bigquery


【解决方案1】:

试试date_trunc:

SELECT date_trunc(last_day(month1st, month), week(monday))
from unnest(GENERATE_DATE_ARRAY('2021-01-01', '2021-12-01', interval 1 month)) AS month1st;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-02
    • 2021-09-22
    • 1970-01-01
    • 2010-09-18
    • 2012-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多