我有四个表 Items、Customer、Invoice_summary、Invoice_details。在这里,我想加入这四个表,并获取特定 item_code 和特定日期范围的 Sum(Invoice_details.Item_quntity) 和 Sum(Invoice_details.Price) 。主要栏目如下:
Invoice_summary :Inv_num,Inv_date,Cus_id,Total
Items :Item_code,Item_name,Unit_price
Invoice_details :Inv_num,Item_code,Item_qty,Price
Customers :Cus_id,Cus_name,Route
这是我目前拥有的。这返回的不止一行(整个项目名称),我只需要特定项目代码。有人可以解释我哪里出错了。
SELECT Invoice_Table.Item_Code, Items.Item_Name,
(Select sum(Invoice_Table.Item_Quntity) from (Invoice_Table INNER JOIN Invoice ON Invoice_Table.Inv_Num = Invoice.Inv_Num) where ((Invoice_Table.Item_Code=[?]) And Invoice.inv_date Between #3/4/2013# And #6/4/2013#) group BY Invoice_Table.Item_Code) AS Quntity,
(Select sum(Invoice_Table.Price) from (Invoice_Table INNER JOIN Invoice ON Invoice_Table.Inv_Num = Invoice.Inv_Num) where ((Invoice_Table.Item_Code=[?]) And Invoice.inv_date Between #3/4/2013# And #6/4/2013#) group BY Invoice_Table.Item_Code) AS Price
FROM Invoice_Table
INNER JOIN Items ON Invoice_Table.Item_Code = Items.Item_Code
GROUP BY Invoice_Table.Item_Code, Items.Item_Name;