首页 > 解决方案 > 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
)

标签: sqlgoogle-cloud-platformgoogle-bigquery

解决方案


在下面试试这个 -

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)

推荐阅读