Google bigquery 如何删除BQ中的空行

Google bigquery 如何删除BQ中的空行,google-bigquery,Google Bigquery,我只是想解决一些简单的例子来提高我在BigQuery中编写查询的技能。在下面的示例中, 我不知道如何删除空行 with table1 as( select "box_1" box, "yellow" colours union all select "box_1" box, "green" colours union all select "box_2" box, "blue" colours union all select "box_2" box, "blue" colours union

我只是想解决一些简单的例子来提高我在BigQuery中编写查询的技能。在下面的示例中, 我不知道如何删除空行

with table1 as(
select "box_1" box, "yellow" colours union all
select "box_1" box, "green" colours union all
select "box_2" box, "blue" colours union all
select "box_2" box, "blue" colours union all
select "box_3" box, "red" colours union all
select "box_3" box, "green" colours union all
select "box_3" box, "blue" colours
)
select array(select box from unnest(x)y where "blue" in unnest(x) limit 1 )box_containing_blue 
from(select box,array_agg(if(colours="blue",colours,null)ignore nulls )x 
from table1 group by box)

我不确定你用这个问题到底想达到什么目的。 但如果这是我所相信的,我想你可以这样简化:

with table1 as(
select "box_1" box, "yellow" colours union all
select "box_1" box, "green" colours union all
select "box_2" box, "blue" colours union all
select "box_2" box, "blue" colours union all
select "box_3" box, "red" colours union all
select "box_3" box, "green" colours union all
select "box_3" box, "blue" colours
)
select distinct box as box_containing_blue from table1 where colours = "blue"

我相信这样的事情应该会奏效

with table1 as(
select "box_1" box, "yellow" colours union all
select "box_1" box, "green" colours union all
select "box_2" box, "blue" colours union all
select "box_2" box, "blue" colours union all
select "box_3" box, "red" colours union all
select "box_3" box, "green" colours union all
select "box_3" box, "blue" colours
)
select array(select box from unnest(x)y where "blue" in unnest(x) limit 1 )as box_containing_blue 
from(select box,array_agg(if(colours="blue",colours,null)ignore nulls )x 
from table1 group by box
having x is not null)

很难改进毫无意义的东西(至少在没有额外细节的情况下)。不要强迫我们猜测-你能解释一下你的预期输出吗?行框\u包含\u blue 1 box \u 2 box \u 3这正是Sourygna的答案为你做的-同时,它与你的脚本产生的结果大不相同:o)