sql - 在 BigQuery 中声明数组常量
问题描述
我正在尝试重构 SQL 查询,而当前查询是
WITH first_result AS (
select table.a,table.b,table.c from table where table.a NOT IN
('x', 'y', 'z',.......1000 more entries)),
second_result AS (....),
SELECT * FROM second_result
如何将['x', 'y', 'z',.......1000 more entries]
分成常数?我想让查询更具可读性
解决方案
最初的问题是关于修复以下查询 -
with first_result as (
select table.a,table.b,table.c from table where table.a not in
['x', 'y', 'z']),
second_result as (....),
select * from second_result
有了答案
您应该使用WHERE a NOT IN UNNEST(['x', 'y', 'z'])
如下示例(BigQuery 标准 SQL)
with first_result as (
select table.a,table.b,table.c from table where table.a not in
UNNEST(['x', 'y', 'z']) ),
second_result as (....),
select * from second_result
推荐阅读
- android - Firestore doc delete 预计会删除 1 个人,但也会删除所有类似的文档
- install4j - 更新现有安装
- python - Python 中的实时语音到文本转录
- c# - “NullReferenceException:对象引用未设置为对象的实例”统一对话系统
- python - 在函数python中将对象作为参数传递
- deep-learning - 在深度学习模型训练中修改学习率
- theorem-proving - 在 Lean Theorem Prover 中定义 `curry`
- google-cloud-platform - 自托管 gitlab-runner 无法在 GKE 上注册自托管 gitlab
- javascript - Rails 中的无限滚动运行次数过多
- javascript - 反应钩子不起作用