DATE_DIFF Bigquery 中的函数可能性

DATE_DIFF Function Possibilities in Bigquery

目前我一直在寻找如何将 Datediff 分组到历史时期。 假设有 2 个人有活动日期:假设今天 Current_date 是 2021-05-17

ID     Active_date   Current_date    Date_diff
10001  2021-05-14    2021-05-17      3
10002  2021-05-12    2021-05-17      5
10002  2021-05-04    2021-05-17      13
10001  2021-05-01    2021-05-17      16

我要显示的是Current_date的历史 - Active_date = Datediff

ID     Active_date   Current_date    Date_diff
10001  2021-05-14    2021-05-17      3
10002  2021-05-12    2021-05-17      5
10002  2021-05-04    2021-05-17      13
10001  2021-05-01    2021-05-17      16
10001  2021-05-14    2021-05-16      2
10002  2021-05-12    2021-05-16      4
10002  2021-05-04    2021-05-16      12
10001  2021-05-01    2021-05-16      15
....... and so on, until Date_diff is zero

如何在 Bigquery/Oracle 上实现此目标?

尝试 generate_date_array:

with mytable as (
  select 10001 as id, date '2021-05-14' as active_date union all
  select 10002, date '2021-05-12'
)
select *, date_diff(curren_date, active_date, day) as diff
from mytable, unnest(generate_date_array(active_date, current_date())) as curren_date