Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
中的BigQuery SQL条件查询_Sql_Google Cloud Platform_Google Bigquery - Fatal编程技术网

中的BigQuery SQL条件查询

中的BigQuery SQL条件查询,sql,google-cloud-platform,google-bigquery,Sql,Google Cloud Platform,Google Bigquery,我一直试图在中构造一个条件的,如下所示,但这给了我一个由多个元素产生的标量子查询错误。我应该如何处理这种类型的查询?这些表是不相关的 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 (
  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)
试试下面这个-

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)

你能给出真实的sql代码吗?我已经更新了问题,使其看起来像真实的代码(尽管我不知道这有什么区别)。你能给出真实的sql代码吗?我已经更新了问题,使其看起来像真实的代码(尽管我不知道这有什么区别)。谢谢!但是如果子查询来自不同的表,会发生什么呢?(请参阅更新)。在表之间建立适当的关系并应用相同的逻辑。“其他表”彼此不相关。显示所有3个表中的样本数据,然后显示它们的预期输出。我认为在这种情况下不需要样本数据(我更喜欢保持问题的干净,没有不必要的信息)。你最新的答案正是我想要的。效果很好。谢谢谢谢但是如果子查询来自不同的表,会发生什么呢?(请参阅更新)。在表之间建立适当的关系并应用相同的逻辑。“其他表”彼此不相关。显示所有3个表中的样本数据,然后显示它们的预期输出。我认为在这种情况下不需要样本数据(我更喜欢保持问题的干净,没有不必要的信息)。你最新的答案正是我想要的。效果很好。谢谢