sql - BigQuery SQL 条件输入
问题描述
我一直在尝试构建一个IN
像下面这样的条件,但这给了我scalar subquery produced more than one element
错误。我应该如何处理这种类型的查询?这些表不相关。
select * from my_table
where my_table.my_col in (
case
when 1 = 1
then (select my_col from my_other_table_1)
else (select my_col from my_other_table_2)
end
)
解决方案
在下面试试这个 -
select * from my_table
where my_table.my_col in (
SELECT
case
when 1 = 1 then my_col_1
else my_col_2
END
from my_other_table
)
由于您的其他表不相关,您可以尝试以下逻辑 -
select * from my_table
where
(1=1 and my_col IN (select my_col_1 from my_other_table_01)
OR
(3=3 and my_col IN (select my_col_2 from my_other_table_02)
推荐阅读
- python - 用 pandas、beautifulsoup、urllib 抓取:如何检索可能嵌入的字段
- json - jq 查询其中键是数据本身的一部分
- javascript - 当我关闭并重新打开弹出窗口时,客户端无数次调用服务器
- python - NLTK PortStemmer 缺少位置参数
- python - 如何获得价值在 selenium python 中动态加载的占位符?
- tfs - 根据标签对待办事项项进行样式设置
- apache-spark - 我应该选择哪种网络来设置 Satndalone Spark 集群
- angular - 如何从Angular中的Forms中遍历控件数组属性
- java - 解决圆之间二维弹性碰撞的简单方法
- python - 系统/pip readline 版本不匹配