sql - 如何在 where 子句 [BigQuery] 中为数组设置条件
问题描述
我的桌子上有一个数组 - 像这样:
我只需要考虑 'top_authors.author' = 'Caivi' 和 'top_authors.total_score' = 3 的行
我试图使用 unnest 函数,但我仍然收到错误“没有匹配的运算符 = 参数类型的签名:ARRAY,STRING。支持的签名:ANY = ANY”
你能帮我解决这个问题吗?
解决方案
您可以unnest()
在where
子句中的子查询中:
where exists (select 1
from unnest(top_authors) ta
where ta.author = 'Caivi' and ta.total_score = 3
)
或者您可以在主查询中执行此操作:
select . . .
from t cross join
unnest(top_authors) ta
where ta.author = 'Caivi' and ta.total_score = 3;
假设您在数组中没有重复项,这些应该会产生等效的结果。
推荐阅读
- node.js - Mongoose 查找从多个集合中获取数据
- c# - Xceed.Words.NET DocX - 将文档添加到 Maindocument 并将编号列表重置为 1
- sql - 将多人插入一个大型数据集
- xml - 如何从父模板中转义整个刀片模板的输出
- python - Python - 为什么我们使用 init 方法而不是自定义构造函数?
- git - 重新定位合并的分支
- amazon-web-services - 尝试构建端到端 jmeter AWS 实例测试架构
- python - Django不同的url去同一个页面
- android - Android中的.pk8文件在哪里
- android - 滚动后 Recyclerview 项目位置 NOT_FOUND