首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >BigQuery SQL conditional IN

BigQuery SQL conditional IN
EN

Stack Overflow用户
提问于 2020-09-16 15:31:44
回答 1查看 52关注 0票数 0

我一直在尝试构造一个如下所示的条件IN,但这给出了scalar subquery produced more than one element错误。我应该如何处理这种类型的查询呢?这些表是不相关的。

代码语言:javascript
运行
复制
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
)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-16 15:42:15

试试下面这个-

代码语言:javascript
运行
复制
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
)

因为你的其他表是不相关的,你可以尝试下面的逻辑-

代码语言:javascript
运行
复制
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)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63915181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档