BigQuery select语句别名在where子句中不起作用

时间:2019-07-11 10:05:50

标签: google-bigquery

我尝试在下面的查询中给出,但是它抛出错误RANK尚未定义。

SELECT
    EmailAddress
  , FirstName
  , LastName
  , RANK() OVER (ORDER BY BookingDate) AS RANK FROM `table_name`
WHERE RANK BETWEEN 5 AND 7

1 个答案:

答案 0 :(得分:3)

以下是用于BigQuery标准SQL

在形成查询输出并分配别名之前先评估WHERE子句,这意味着rank时字段WHERE rank BETWEEN 5 AND 7不可用。

您只需要在下面使用

#standardSQL
SELECT * FROM (
  SELECT
      EmailAddress
    , FirstName
    , LastName
    , RANK() OVER (ORDER BY BookingDate) AS rank 
  FROM `project.dataset.table`
)
WHERE rank BETWEEN 5 AND 7