1
私は3つのテーブルtable1、table2、table3を持っています。同じ構造を持っています。私は1つの列に基づいて行を比較したいです。テーブル複数のテーブルを単一の列postgresqlに基づいて比較する
TABLE1
country_code country_name rate vendor
91 india 2.0 abc
92 pak 1.0 abc
table2の
country_code country_name rate vendor
91 india 2.1 abc1
92 pak 1.1 abc1
93 afgan 1.1 abc1
表3
country_code country_name rate vendor
91 india 2.2 abc2
92 pak 1.2 abc2
93 afgan 1.2 abc2
880 bang 1.2 abc2
desired output is
country_code country_name rate vendor rate vendor rate vendor
91 india 2.0 abc 2.1 abc1 2.2 abc2
92 pak 1.0 abc 1.1 abc1 1.2 abc2
93 afgan 1.1 abc1 1.2 abc2
880 bang 1.2 abc2
の
構造は、私は完全外部結合を試みたが、目的の結果を取得できませんでした。 私は
SELECT *
FROM table1 a
FULL OUTER JOIN table2 b ON a.country_code=b.country_code
FULL OUTER JOIN table3 c ON c.country_code=a.country_code ;
このクエリを使用し、上記のクエリの結果は
91 india 2 91 india 2.1 91 india 2.2
92 pak 1 92 pak 1.1 92 pak 1.2
93 afgan 1.1
880 bang 1.2
93 afgan 1.2
ですが、私は、これは動作するはず
91 india 2 91 india 2.1 91 india 2.2
92 pak 1 92 pak 1.1 92 pak 1.2
93 afgan 1.1 93 afgan 1.2
880 bang 1.2
このクエリの意志私たちがoのデータを変更するとうまくいかない私はtable2またはtable3でないいくつかの行を持っている場合は、私たちは望んだ結果を得ることはありません。動的クエリを提供してください –
私はクエリを変更しました。あなたは[このリンク](http://stackoverflow.com/a/21565284/7689902)を見ることもできます。 –