Select 使用;选择“如果”;winth另一个数据集

Select 使用;选择“如果”;winth另一个数据集,select,if-statement,google-bigquery,Select,If Statement,Google Bigquery,我试图在BigQuery中执行此查询 我有一张桌子1和一张桌子2。我想这样做: 如果(使用特定条件选择表2)返回>0条记录 then perform this select on table 1 (select one), 否则,对表1执行另一个选择(选择2) 我可以这样做: SELECT IF (1=1,"YES", "NO"), but, when I replace 1=1 with my select, like this: SELECT IF ((SELECT count(

我试图在BigQuery中执行此查询

我有一张桌子1和一张桌子2。我想这样做:

如果(使用特定条件选择表2)返回>0条记录

   then perform this select on table 1 (select one), 
否则,对表1执行另一个选择(选择2)

我可以这样做:

SELECT IF (1=1,"YES", "NO"), but, when I replace 1=1 with my select, like this:

SELECT IF ((SELECT count(*) FROM Table1)>0,"YES", "NO")
SELECT 
    IF(inner_table.count_column > 0, "YES", "NO)  -- here we select the 'count_column' from 'inner_table
FROM   
(   
    (SELECT count(*) as count_column FROM table1) 
) as inner_table -- aliasing the inner select as 'inner_table'
不再工作了

有什么帮助吗???我希望任何专家都能帮助我

致以最良好的祝愿


Albert

不能有这样的嵌套select语句。需要做的是,您的内部select必须是一个子查询并具有别名 比如:

SELECT IF (1=1,"YES", "NO"), but, when I replace 1=1 with my select, like this:

SELECT IF ((SELECT count(*) FROM Table1)>0,"YES", "NO")
SELECT 
    IF(inner_table.count_column > 0, "YES", "NO)  -- here we select the 'count_column' from 'inner_table
FROM   
(   
    (SELECT count(*) as count_column FROM table1) 
) as inner_table -- aliasing the inner select as 'inner_table'
希望这是有意义的。这就是bigquery的工作原理,您需要将嵌套语句构造成子查询。 这里有一些阅读材料