【发布时间】:2021-11-25 18:35:14
【问题描述】:
如何获取over子句中窗口函数给出输出的同一行的整行或其他列值。
例如
with o as (
select date from unnest(GENERATE_TIMESTAMP_ARRAY('2021-01-01 00:00:00',current_timestamp(),interval 1 hour)) as date
enter code here
), p as (
select *,RAND()*100 as Number from o
), q as (
select *,max(number) over(order by date) as best from p
order by date
)
select * from q
使用上面的查询,我得到的输出是最好的值,它在按时间戳排序时定义了我上面的最大数量。
上列的输出:
我使用 over 函数计算了最佳值,但我还想要日期列在哪一天最好。
【问题讨论】:
-
我了解,您需要另一列 best_date 例如 (2021-01-01 21:00:00 UTC)?
标签: sql google-bigquery max window-functions