配置单元加入分区

我有这两个表:

table products
(
product_id bigint,product_name string
)
partitioned by (product_category as string)

table place_of_sale
(
product_id bigint,city string
)
partitioned by (country as string)

如何基于“ product_id”离开两个表,但将其放置在表place_of_sale的分区“国家”上?

这是一个预期结果的示例:

table products
product_id      product_name    product_category
1000            banana          fruit
1001            coconut         fruit
1002            ananas          fruit
2002            cow             animal
2003            beef            animal


table place_of_sale
product_id      city        country
1000            Texas       USA
1002            Miami       USA
2003            Sydney      Australia


desired result for a left join between table products and table place_of_sale over the partition country :

product_id      product_name        product_category    city   country
1000            banana              fruit               Texas  USA
1001            coconut             fruit               null   null
1002            ananas              fruit               Miam   USA

2002            cow                 animal              null   null
2003            beef                animal              Sydney Australia

在此示例中仅给出了两个不同的国家,但可以想象有很多不同的国家。 这就像在每个国家/地区执行左联接,然后在所有国家/地区的结果之间进行联合一样。

yanguoliu 回答:配置单元加入分区

如果所售产品是表place_of_sale中存在的产品,请使用LEFT JOIN:

select s.country,p.product_id,p.product_name,p.category,case when s.product_id is NULL then "not sold" else "sold" as sold 
 from products p
      left join place_of_sale s on p.product_id = s.product_id 
 order by country,product_id --order if necessary
本文链接:https://www.f2er.com/3156700.html

大家都在问