我正在使用Microsoft Access并且遇到此方案有困难有两个原因:
对于我的代码,我们非常感谢任何建议:
SELECT
Product.PID,
Product.Code,
COUNT (SalesOrder.PID) AS Ordered,
SUM (ExtendedPrice) AS [Value],
SUM (NbrItemsRequested) AS Requested
FROM Product, SalesOrderProduct
WHERE
Product.PID = SalesOrderProduct.PID
GROUP BY
Product.PID, Product.Code
ORDER BY
Requested;
答案 0 :(得分:0)
如果出现一个询问SalesOrder.PID值的弹出框,则表示Access无法在您查询中包含的表格中的任何位置识别该列。换句话说,您没有计算SalesOrder.PID,因为Access没有认识到这一点。我建议您检查列名以确保它们是正确的。
答案 1 :(得分:0)
This should fix it.
SELECT Product.PID, Product.Code,
COUNT (SalesOrderProduct.PID) AS Ordered,
SUM (ExtendedPrice) AS [Value],
SUM (NbrItemsRequested) AS Requested
FROM Product inner join SalesOrderProduct on Product.PID = SalesOrderProduct.PID
GROUP BY Product.PID, Product.Code
ORDER BY Requested;
答案 2 :(得分:0)
出现弹出框,因为SalesOrder.PID
引用了不在SalesOrder
子句中的表from
。大概你的意思是SalesOrderProduct
。
您还应该在查询中使用显式连接,并为所有列使用表别名:
SELECT p.PID, p.Code, COUNT(sop.PID) AS Ordered,
SUM(sop.ExtendedPrice) AS [Value],
SUM(sop.NbrItemsRequested) AS Requested
FROM Product as p inner join
SalesOrderProduct as sop
on p.PID = sop.PID
GROUP BY p.PID, p.Code
ORDER BY SUM(sop.NbrItemsRequested);
我不确定order by
无法正常工作的意思,但我猜测将公式替换为别名将解决问题。
注意:以上是猜测ExtendedPrice
和NbrItemsRequested
的来源。