Как убрать пустую строку в БК - PullRequest
0 голосов
/ 16 мая 2018

Я просто пытаюсь решить простые примеры, чтобы улучшить мои навыки написания запросов в 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)

Ответы [ 2 ]

0 голосов
/ 16 мая 2018

Я верю, что что-то подобное должно сработать

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)
0 голосов
/ 16 мая 2018

Я не уверен, что вы действительно пытаетесь достичь с помощью этого запроса. Но если я верю в это, я думаю, вы могли бы упростить это так:

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"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...