我有一個要求從Access數據庫中提取產品數量總數,但包括供應商名稱,ID號,說明等等以及數量總和。我們如何通過查詢選擇sum()/ group中的多個列?
我有這樣的查詢:
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]
正在運行但更改結果太多。什麼是處理這個查詢的適當方式?
另外,如果可以的話,擺脫字段(列)名稱中的空格。他們會慢慢推動你堅持從任何方面打字方括號。 – Fionnuala 2012-07-31 09:14:53
當然,如果它是我的數據庫,我不會有空間。謝謝 – Chaddeus 2012-07-31 14:36:28