2012 年 11 月の 14,028 行のテーブルがあります。また、2013 年 3 月の 13,959 行のテーブルもあります。単純なNOT IN()
句を使用して、誰が去ったかを確認しています。
select * from nov_2012 where id not in(select id from mar_2013)
これは 396 行を返しました。失われたメンバーのすべての ID を取得して一時テーブル ( ##lost
) に配置したところ、実際には 32 人がまだmar_2013
テーブルに残っていました。以下を使用してIDを検索すると、それらを引き上げることができます。
select * from mar_2013 where id in(select id from ##lost)
何が起こっているのかわかりません。私がid
作成したフィールドはIDENTITY
列です。を使用したマッチングに影響がありNOT IN
ますか? テーブル間の行の欠落をチェックするより良い方法はありますか? 私も試しました:
select a.* from nov_2012 a left join mar_2013 b on b.id = a.id where b.id is NULL
そして、同じ結果を受け取りました。
これが ID フィールドの作成方法です。
create table id_lookup( dateofcusttable date ,sin int ,sex varchar(12) ,scid int identity(777000,1))
insert into id_lookup (sin, sex) select distinct sin, sex from [Client Raw].dbo.cust20130331 where sin <> 0 order by sin, sex
これは、scid を行進テーブルに追加する方法です。
select scid, rowno as custrowno
into scid_20130331
from [Client Raw].dbo.cust20130331 cust
left join id_lookup scid
on scid.sin = cust.sin
and scid.sex = cust.sex
update scid_20130331
set scid = custrowno where scid is NULL --for members who don't have more than one id or sin information is not available
drop table Account_Part2_Current
select a.*, scid
into Account_Part2_Current
from Account_Part1_Current a
left join scid_20130331 b
on b.custrowno = a.rowno_custdmd_cust
次に、すべての情報を scid でグループ化します