[英]Is there a way to have 1 to many relationship join in Big Query? I want to repeat values using full outer join but it returns inner join
您可以通過分別連接每個表然后對這些結果應用聯合來實現所需的輸出。您可以嘗試以下查詢:
詢問:
create temp table main as (
select 1 ranking, 'apple' keyword, 500 total_purchase union all
select 2,'banana', 477 union all
select 3, 'milk', 456
);
create temp table t1 as (
select 1 ranking, 'apple' keyword, 55 purchase, 1 store union all
select 2,'beer', 42 ,1 union all
select 3, 'chips', 33 ,1
);
create temp table t2 as (
select 1 ranking, 'apple' keyword, 51 purchase, 2 store union all
select 2,'banana', 43 ,2 union all
select 3, 'bread', 34 ,2
);
select m.*,t.purchase,first_value(Store ignore nulls) over
( order by m.ranking) store from main m
left join t1 t on m.keyword = t.keyword
union all
select m.*,t.purchase,first_value(Store ignore nulls) over( order by
m.ranking) store from main m
left join t2 t on m.keyword = t.keyword
輸出:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.