gpt4 book ai didi

arrays - 如何在 BigQuery 中声明列表/数组/结构类型变量

转载 作者:行者123 更新时间:2023-12-03 21:16:57 24 4
gpt4 key购买 nike

如何在 BigQuery 中声明列表类型变量,以便我可以在 where 子句中使用它?我有这个代码

WITH
subquery AS (
SELECT
1 AS col1
UNION ALL
SELECT
2 AS col1
UNION ALL
SELECT
3 AS col1 )

SELECT
col1
FROM
subquery
WHERE
col1 IN (1, 2)

相反,我想在查询中使用变量
DECLARE list ARRAY;
SET list = (1,2);

WITH
subquery AS (
SELECT
1 AS col1
UNION ALL
SELECT
2 AS col1
UNION ALL
SELECT
3 AS col1 )

SELECT
col1
FROM
subquery
WHERE
col1 IN list

我试过 DECLARE list STRUCT [less than] int64,int64 [greater than] 它不接受

最佳答案

试试下面的代码:

DECLARE list ARRAY <INT64>;
SET list = [1,2];

WITH
subquery AS (
SELECT
1 AS col1
UNION ALL
SELECT
2 AS col1
UNION ALL
SELECT
3 AS col1 )

SELECT
col1
FROM
subquery
WHERE
col1 IN UNNEST(list)

关于arrays - 如何在 BigQuery 中声明列表/数组/结构类型变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59614517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com