我需要从 Access DB 中提取总数量的产品数量,但包括供应商名称、ID 号、描述等......以及数量总和。
我有一个这样的查询:
SELECT [Vendor Name], SUM([Quantity]) AS Total
FROM [SalesDB]
WHERE [Vendor No] IN (1,2,3,4,5,6,7,8) AND [Item Description] = 'bolts'
Group By [Vendor Name]
效果很好......除了我需要在查询中提取更多列,如下所示:
SELECT [Vendor Name], [Vendor No], [Item No], [Item Description], [Item Cost], [Quantity], SUM([Quantity]) AS Total
FROM [SalesDB]
WHERE [Vendor No] IN (1,2,3,4,5,6,7,8) AND [Item Description] = 'bolts'
Group By [Vendor Name]
不起作用,引发聚合错误
所以改为这样做:
SELECT [Vendor Name], [Vendor No], [Item No], [Item Description], [Item Cost], [Quantity], SUM([Quantity]) AS Total
FROM [SalesDB]
WHERE [Vendor No] IN (1,2,3,4,5,6,7,8) AND [Item Description] = 'bolts'
Group By [Vendor Name], [Vendor No], [Item No], [Item Description], [Item Cost], [Quantity]
哪个运行但改变结果太多。处理此查询的适当方法是什么?