postgreSQLを最近使い始めた者です。
データ更新の検証を行うため、2つのテーブルでキーの合致している件数を調べました。
wrk01,wrk02ともpcnmとpcdateがprimary keyです。
SQL
1select count(*) from wrk01 a inner join wrk02 b 2on a.pcdate=b.pcdate and a.pcnm = b.pcnm; 3 4```の結果は count 3951 5 6```SQL 7select count(*) from wrk01 a left join wrk02 b 8on a.pcdate=b.pcdate and a.pcnm = b.pcnm 9where b.pcdate is null and b.pcnm is null; 10 11```の結果は count 1480 12 13```SQL 14select count(*) from wrk01;
の結果は count 5411 3951 + 1480 = 5431 で合致しません。
SQL
1select count(*) from wrk01 a where exists ( 2select * from wrk02 b where a.pcdate=b.pcdate and a.pcnm = b.pcnm); 3 4```の結果は count 3931 5```SQL 6select count(*) from wrk01 a where not exists ( 7select * from wrk02 b where a.pcdate=b.pcdate and a.pcnm = b.pcnm); 8 9```の結果は count 1480 10 11で、3931 + 1480 = 5411 で合致します。 12 13PostgreSQLはnullの取り扱いが微妙に他のDBと異なるという記事は目にしましたが、 14通常の内部結合にも影響を及ぼすことがあるのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/16 05:07