SQL:总量和SUM [英] SQL: total quantity and SUM

查看:97
本文介绍了SQL:总量和SUM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。

在AdventureWorks2012数据库上,我必须使用Purchasing.PurchaseOrderDetail表编写查询,并列出在此期间每种产品的总购买量2006年,标签总和为TotatQtyPurchased。我还必须按ProductID分组。

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.

这是我的工作

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

但我一直收到错误消息:
消息102,级别15,状态1,第4行'*'附近的语法不正确。

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

我在做什么错?谢谢。

推荐答案

您在选择列表的第一字段和第二字段之间省略了逗号。

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

这篇关于SQL:总量和SUM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆