我需要选择多个列作为LEAD语句的一部分。看起来效率真的很低,将所需的排序和分区数量增加了三倍->
SELECT
field,
field2,
field3,
LEAD(field, 1) OVER (PARTITION BY field ORDER BY field ASC) AS nextField,
LEAD(field2, 1) OVER (PARTITION BY field ORDER BY field ASC) AS nextField2,
LEAD(field3, 1) OVER (PARTITION BY field ORDER BY field ASC) AS nextField3,
FROM dataset.table
最佳答案
有两点可以补充米哈伊尔的答案:
SELECT
field,
field2,
field3,
LEAD(field, 1) OVER w1 AS nextField,
LEAD(field2, 1) OVER w1 AS nextField2,
LEAD(field3, 1) OVER w1 AS nextField3,
FROM dataset.table
WINDOW w1 AS (PARTITION BY field ORDER BY field ASC)
*不能真正给您确定日期,但是此刻正在内部测试中,因此不应太长。
关于google-bigquery - 重复使用BigQuery窗口函数分区,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35513133/