SQL: total quantity and SUM

别说谁变了你拦得住时间么 提交于 2019-12-25 18:52:53

问题


I have a question.

On the AdventureWorks2012 database, I have to write a query using the Purchasing.PurchaseOrderDetail table and list the total quanity purchased for each product during 2006 and label sum as TotatQtyPurchased. I also have to group by ProductID.

Here is my work

SELECT POD.ProductID SUM(*) TotalQtyPurchased 
FROM Purchasing.PurchaseOrderDetail POD
WHERE Date = '2006' GROUP BY POD.ProductID

But I keep getting an error message: Msg 102, Level 15, State 1, Line 4 Incorrect syntax near '*'.

What am I doing wrong? Thanks.


回答1:


You've left out a comma between the first and second fields in the "select" list.

SELECT POD.ProductID,
 SUM(*) TotalQtyPurchased 
FROM Purchasing.PurchaseOrderDetail POD 
WHERE Date = '2006' 
GROUP BY POD.ProductID


来源:https://stackoverflow.com/questions/20499184/sql-total-quantity-and-sum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!