【问题标题】:Bigquery YTD WORKDAYS calculationBigquery YTD WORKDAYS 计算
【发布时间】:2021-08-16 07:55:40
【问题描述】:

我使用下面的计算来计算一个月的工作日。 即日历日期 = 28-05-2021,我得到 23 天(星期一到星期五)

(select count(*) from unnest(generate_date_array(date_trunc(CALENDAR_DATE, month), last_day(CALENDAR_DATE, month ))) day
where not extract(dayofweek from day) in (1, 7)) as Workdays_Month,

我想根据日历日期计算 YTD Workdays IE 如果日历日期 = 28-05-2021,则 YTD 工作日将是财政年度月(7 月 20 日至 5 月 21 日)工作日的总和。

【问题讨论】:

    标签: sql google-bigquery


    【解决方案1】:

    假设您的财政年度从 7 月开始 - 您可以在下面使用

    select count(*) 
    from unnest([struct(extract(year from current_date) as year, extract(month from current_date) as month)]),
    unnest(generate_date_array(if(month < 7, date(year - 1, 7, 1), date(year, 7, 1)), last_day(date(year, month, 1)))) day
    where not extract(dayofweek from day) in (1, 7)   
    

    【讨论】:

      猜你喜欢
      • 2021-09-15
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多