我有一个查询,我需要在查询中反复使用字符串列表,并想声明一次,唯一的问题是我只让它像第二个例子中那样工作,不想取消
DECLARE
list X DEFAULT (
8335, 9776, 11496);
SELECT * FROM `dataset.table` WHERE quantity_sold IN list
X不确定它必须是什么类型的
DECLARE
list ARRAY<INT64> DEFAULT [
8335, 9776, 11496];
SELECT * FROM `dataset.table` WHERE quantity_sold IN UNNEST(list)
这是"技巧";我通常在这种情况下使用
with my_variables as (
select [8335, 9776, 11496] list1, ['a', 'b', 'c'] list2
# note: this is just one row CTE
)
select *
from `dataset.table`, my_valiables
where quantity_sold in unnest(list1)
and something_else in unnest(list1)
and yet_another_one in unnest(list2)