[英]merge and dedup two tables in sql
我需要合並兩個表。 這個想法是表b的得分被默認使用,只有來自表a的行具有相同的組pid,但是不同的得分被添加到表b中。
表一
group pid score country
--------------------------------------
T1 aa 10.1 US
T1 aa 10.1 FR
T1 aa 10.1 UK
T1 aa 10.1 CS
T1 aa 16.2 BR
表b
group pid score country
--------------------------------------
T1 aa 10.1 Default
所需結果:
group pid score country
--------------------------------------
T1 aa 10.1 Default
T1 aa 16.2 BR
一種方法是union all
not exists
:
select b.*
from b
union all
select a.*
from a
where not exists (select 1
from b
where b.group = a.group and
b.pid = a.pid
b.score = a.score
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.