【问题标题】:bigquery lead window function is there any way to use a table value as the offset?bigquery 引导窗口函数有没有办法使用表值作为偏移量?
【发布时间】:2021-05-17 00:01:34
【问题描述】:

我想知道 bigquery 标准 sql 中的前导窗口函数是否有任何解决方法可以使用表值而不是文字或查询参数?

select 
artcl
,days
,lead(days,ofst)over(partition by artcl order by days) as tst
from(
    select 123 as artcl, 1 as days ,2 as ofst
    union all
    select 123 as artcl, 2 as days ,2 as ofst
    union all
    select 123 as artcl, 3 as days ,2 as ofst
)

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    您可以使用以下方法

    select artcl, days, ofst,
      arr[safe_offset(row_number() over(partition by artcl order by days) + ofst - 1)] as tst
    from `project.dataset.table`
    join (
      select artcl, array_agg(days order by days) arr, 
      from `project.dataset.table`
      group by artcl
    )
    using(artcl)
    

    【讨论】:

    • 考虑也投票赞成有帮助的答案
    猜你喜欢
    • 1970-01-01
    • 2011-06-09
    • 1970-01-01
    • 2021-02-03
    • 2023-02-09
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 2021-04-28
    相关资源
    最近更新 更多