嘿,我想回答这个问题
撰写查询以计算每种成品的原材料总成本。在结果表中,我们希望查看产品ID,产品名称及其原材料总成本。按原始物料的总成本按降序对结果进行排序。
这就是我所拥有的
SELECT Product_t.Product_ID, Product_t.Product_Name, SUM(Uses_t.Footage * Raw_Materials_t.Unit_price ) AS Total_Cost_Of_Raw_Materials
FROM Product_t, Uses_t, Raw_materials_t
WHERE Product_t.Product_ID=Uses_t.Product_ID and Uses_t.Material_ID=Raw_materials_t.Material_ID
GROUP BY Product_ID
ORDER BY SUM(Raw_Materials_t.Unit_price * Uses_t.Footage) DESC;
弹出错误指定的字段Product_ID可以引用SQL语句的FROM子句中列出的多个表。
我以为我已经解决了这个问题,但显然它没有用 谢谢你的帮助!!
答案 0 :(得分:0)
如果您正在学习SQL,MS Access是一个糟糕的数据库。它有特殊性。我认为查询看起来像这样:
SELECT p.Product_ID, p.Product_Name,
SUM(u.Footage * m.Unit_price) AS Total_Cost_Of_Raw_Materials
FROM (Product_t as p INNER JOIN
Uses_t as u
ON p.Product_ID = u.Product_ID
) INNER JOIN
Raw_materials_t as m
ON u.Material_ID = m.Material_ID
GROUP BY p.Product_ID, p.Product_Name,
ORDER BY SUM(m.Unit_price * u.Footage) DESC;