2つの異なるselectステートメントを持つ2つのテーブルがあります。これらのテーブルには1つの列しか含まれていません。私はから行を減算したいtable2
の行からtable1
一度だけ。言い換えれば、すべてではなく、1つのオカレンスだけを削除したいと思います。
表1:
apple
apple
orange
表2:
apple
pear
結果:
apple
orange
基本的にはFYI場合はA={A,A,O},B={A,P}
、その後A-B
、論理的です
select * from t1 except select * from t2
これを試して !
create table #t(id varchar(10))
create table #t1(id1 varchar(10))
insert into #t values('apple'),('apple'),('orange')
insert into #t1 values('apple'),('pear')
select * from
(
select *,rn=row_number()over(partition by id order by id) from #t
except
select *,rn1=row_number()over(partition by id1 order by id1) from #t1
)x
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加