[英]How can I paginate this BigQuery query using the rownumber?
How can this BigQuery query be updated to allow for the additional clause for pagination? 如何更新此BigQuery查询以允许其他分页语句?
SELECT test.id, test.city, ROW_NUMBER() OVER () rownumber FROM prod.test LEFT OUTER JOIN prod.locations AS location ON (test.city = location.id)
WHERE active = true
AND rownumber BETWEEN 10000 AND 30000
The resulting error is: 产生的错误是:
Unrecognized name: rownumber 无法识别的名称:行号
For this example, use a subquery: 对于此示例,使用子查询:
SELECT t.*
FROM (SELECT test.id, test.city, ROW_NUMBER() OVER () rownumber
FROM prod.test LEFT OUTER JOIN
prod.locations location
ON test.city = location.id
WHERE active = true
) t
WHERE rownumber BETWEEN 10000 AND 30000 ;
However, you should probably be using LIMIT
and OFFSET
. 但是,您可能应该使用LIMIT
和OFFSET
。
you can also use CTE 您也可以使用CTE
with cte as
(
SELECT test.id, test.city, ROW_NUMBER() OVER () rownumber
FROM prod.test LEFT OUTER JOIN prod.locations AS location ON (test.city = location.id)
WHERE active = true
) select * from cte where rownumber BETWEEN 10000 AND 30000
rownumber is a inline alias which not supported in where clause directly rownumber是直接在where子句中不支持的内联别名
You can use this standard sql clause if bigquery supports it, 如果bigquery支持,则可以使用此标准sql子句,
SELECT
test.id
,test.city
FROM prod.test as test
LEFT OUTER JOIN prod.locations AS location ON (test.city = location.id)
WHERE active = true
order by test.id
offset 10000 rows fetch next 20000 rows only
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.