Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 计算一个客户的订单数量(客户名称)_Sql - Fatal编程技术网

Sql 计算一个客户的订单数量(客户名称)

Sql 计算一个客户的订单数量(客户名称),sql,Sql,计算客户名为“Smith”的客户的订单数量 Oid Odate Oprice Oqty Customer 1 12/22/2005 160 2 Smith 2 08/10/2005 190 2 Johnson 3 07/13/2005 500 5 Baldwin 4 07/15/2005 420 2 Smith 5 12/22/2005 1000 4 Wood 6 1

计算客户名为“Smith”的客户的订单数量

Oid  Odate      Oprice  Oqty  Customer
1    12/22/2005 160     2     Smith
2    08/10/2005 190     2     Johnson
3    07/13/2005 500     5     Baldwin
4    07/15/2005 420     2     Smith
5    12/22/2005 1000    4     Wood
6    10/02/2005 820     4     Smith
7    11/03/2005 200     2     Baldwin

要从表中选择一个项目,请使用如下
select
语句:

SELECT SUM(Oqty) 
from YOUR_TABLE_NAME 
where Customer='Smith' 
GROUP BY Customer,Oqty

请说明您希望结果是3还是8。对列Customer使用COUNT()函数将导致3。在Customer='Smith'的qty列上使用SUM()函数将得到8。
SELECT SUM(Oqty) 
from YOUR_TABLE_NAME 
where Customer='Smith' 
GROUP BY Customer,Oqty