0

私は3つのテーブルを持っています

  1. Payment_Schedule (Event_ID、Event_Type、Event_Incharge、Event_Date)
  2. Product_AMC (AMC_ID、Customer_ID)
  3. Item_Order (注文 ID、顧客 ID)

Payment_Schedule のレコードの場合、Event_ID は AMC_ID または Order_ID です。Event_ID が AMC_ID の場合、Event_Type は「AMC」になり、Order_ID の場合、Event_Type は「Order」になります。

ここでの問題は、Payment_Schedule のすべてのフィールドとともに Customer_ID を取得する方法がわからないことです。

MS Access 2003 を使用しています。助けてください。

4

1 に答える 1

2

すべての顧客とそのすべての payment_schedules を表示

select PS.Event_ID, PS.Event_Type, PS.Event_Incharge, PS.Event_Date, PA.Customer_ID
from (Product_AMC PA
inner join Payment_Schedule PS on (PS.Event_Type='AMC' and PS.Event_ID=PA.AMC_ID))
union all
select PS.Event_ID, PS.Event_Type, PS.Event_Incharge, PS.Event_Date, IO.Customer_ID
from (Item_Order IO
inner join Payment_Schedule PS on (PS.Event_Type='Order' and PS.Event_ID=IO.Order_ID))
order by Customer_ID

1 人の顧客の場合は、「ABC」と発声します

select PS.Event_ID, PS.Event_Type, PS.Event_Incharge, PS.Event_Date, PA.Customer_ID
from (Product_AMC PA
inner join Payment_Schedule PS on (PS.Event_Type='AMC' and PS.Event_ID=PA.AMC_ID))
where PA.Customer_ID = 'ABC'
union all
select PS.Event_ID, PS.Event_Type, PS.Event_Incharge, PS.Event_Date, IO.Customer_ID
from (Item_Order IO
inner join Payment_Schedule PS on (PS.Event_Type='Order' and PS.Event_ID=IO.Order_ID))
where IO.Customer_ID = 'ABC'
于 2012-10-07T05:30:54.760 に答える