私は4つのテーブルを持っています:
注文:
OrderID Detail Discount
------------------------
1001 xxx True
1002 xxx True
1003 xxx True
1004 xxx False
1005 xxx True
1006 xxx True
OrderDiscounts:
OrderID DiscountTypeID DiscountID
----------------------------------
1001 1 8
1002 2 12
1003 1 9
1005 2 13
1006 2 9
クーポン(DiscountTypeID = 1
):
CouponID Title
------------------------
8 CouponTitle8
9 CouponTitle9
キャンペーン(DiscountTypeID = 2
):
CampaignID Title
--------------------------
9 CampaignTitle9
12 CampaignTitle12
13 CampaignTitle13
4つのテーブルすべてを1つのテーブルにマージするクエリが必要です。これにより、次のような結果が得られます。
結果:
OrderID Discount DiscountType DiscountTitle
-----------------------------------------------------
1001 True Coupon CouponTitle8
1002 True Campaign CampaignTitle12
1003 True Coupon CouponTitle9
1004 False
1005 True Campaign CampaignTitle13
1006 True Campaign CampaignTitle9
一部のクーポンIDがキャンペーンIDとして存在する場合があることに注意してください。このシナリオでは、CouponIDとCampaignIDの両方に「9」が存在します。
必要なクエリに加えて、クエリを作成するときにそのようなコマンドを使用する方法/理由についての適切な説明は、答えを探すだけでなく、自分でも同様のシナリオを処理したいので、すばらしいでしょう。ありがとう!