在 BigQuery 中获取星期几的日期

Get the date of the weeks monday for a date in BigQuery

我有一组日期,我需要获取 BigQuery 中同一周的星期一日期。示例:

2021-02-07  -->  2021-02-07
2021-02-08  -->  2021-02-07
2021-02-09  -->  2021-02-07
2021-02-10  -->  2021-02-07
...

我怎样才能得到这个? 到目前为止,我已经能够通过以下 sql 获得周数,但不能获得日期: 摘录(来自 Fecha 的周(星期一))

考虑以下简单方法

select date, 
  date_trunc(date, week(sunday)) date_monday,
  date_trunc(date, week(tuesday)) date_wednesday
from your_table    

如果适用于您问题中的样本数据,如

with your_table as (
  select date '2021-02-07' date union all
  select '2021-02-08' union all
  select '2021-02-09' union all
  select '2021-02-10' 
)           

输出是