小编Raf*_*ski的帖子

BigQuery FIRST_VALUE 和 IGNORE_NULLS - 为什么这样工作?

我的问题是从某个窗口的列中找到第一个值,这里是带查询的示例数据:

WITH finishers AS
 (SELECT 'Bob' as name,
  TIMESTAMP '2016-10-18 2:51:45' as finish_time,
  'F30-34' as division
  UNION ALL SELECT NULL, TIMESTAMP '2016-10-18 2:54:11', 'F35-39'
  UNION ALL SELECT 'Mary', TIMESTAMP '2016-10-18 2:59:01', 'F35-39'
  UNION ALL SELECT 'John', TIMESTAMP '2016-10-18 3:01:17', 'F35-39')
SELECT *,
 FIRST_VALUE (name IGNORE NULLS) OVER(PARTITION BY division ORDER BY finish_time) AS fastest_in_division
FROM finishers
ORDER by division
Run Code Online (Sandbox Code Playgroud)

结果是:

Row name    finish_time             division  fastest_in_division    
1   Bob     2016-10-18 02:51:45 UTC F30-34    Bob    
2   null    2016-10-18 02:54:11 UTC F35-39    **null**   
3 …
Run Code Online (Sandbox Code Playgroud)

google-bigquery

7
推荐指数
1
解决办法
4146
查看次数

标签 统计

google-bigquery ×1