0

我有 3 张桌子

  1. Payment_Schedule(Event_ID、Event_Type、Event_Incharge、Event_Date)
  2. Product_AMC(AMC_ID、Customer_ID)
  3. Item_Order (Order_ID, Customer_ID)

对于 Payment_Schedule 中的记录,Event_ID 是 AMC_ID 或 Order_ID。如果 Event_ID 是 AMC_ID,则 Event_Type 将为“AMC”,如果是 Order_ID,则 Event_Type 将为“Order”。

现在我的问题是我不知道如何获取 Customer_ID 以及 Payment_Schedule 的所有字段。

我正在使用 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

对于单个客户,说“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 回答