GBQ窗口函数和算术运算

时间:2015-07-21 12:38:13

标签: sql google-bigquery window-functions

有谁知道是否可以对使用GBQ窗口函数导出的结果进行任何算术运算?

例如,我可以使用伪代码将row_number增加100(某个数字),如下所示:

SELECT 100 + ROW_NUMBER() OVER (PARTITION BY X ORDER BY x_id DESC) increased_row_num
FROM Table1
...

2 个答案:

答案 0 :(得分:5)

您需要使用子查询

SELECT 100 + row_num AS increased_row_num FROM (
SELECT ROW_NUMBER() OVER (PARTITION BY X ORDER BY x_id DESC) AS row_num
FROM Table1
)

答案 1 :(得分:0)

  

但我希望还有另一种解决方案

使用BigQuery Standard SQL预期功能现在可以正常工作

#standardSQL
SELECT 100 + ROW_NUMBER() OVER (PARTITION BY X ORDER BY x_id DESC) increased_row_num
FROM Table1

请参阅Enabling Standard SQLMigrating from legacy SQL