次のようなテーブルがあります。
ManufacturerID ProductID Price Region
==============================================
100 1 12.00 A
100 2 20.00 A
100 3 25.00 A
100 4 30.00 B
101 1 15.00 A
101 2 20.00 A
101 4 30.00 B
2 つの異なるメーカーを比較して、次のようなクエリ結果を取得したいと考えています。
ProductID Price1 Price2 Region
=========================================================================
1 12.00 15.00 A
2 20.00 20.00 A
3 25.00 null A
4 30.00 30.00 B
同じテーブルで左結合を使用しようとしています:
SELECT ProductID, a.Price AS Price1, b.Price AS Price2, a.Region
FROM table1 a
LEFT JOIN table1 b ON a.ProductID = b.ProductID AND a.ManufacturerID = 100
WHERE b.ManufacturerID = 101
しかし、これは製造元 101 の不足している製品 (ID:4) を提供しません。何が不足していますか?