sql - 订单总和

时间:2017-01-11 07:45:56

标签: mysql sql

Name      | count
Charlie      10
Charlie       5
Barney        6
Disney        7

我正在寻找一个sql查询,它将对每个名称的总和求和,并按计数的降序打印

4 个答案:

答案 0 :(得分:0)

select sum(count) as total
from tablename
group by Name;

答案 1 :(得分:0)

SELECT SUM(count) as Count FROM table 
GROUP BY Name 
ORDER BY SUM(count) DESC

答案 2 :(得分:0)

使用下一个查询

SELECT Name, SUM(count) 
FROM mytable 
GROUP BY Name 
ORDER BY SUM(count) DESC

答案 3 :(得分:0)

您可以使用此查询:

SELECT Name, SUM(count) 
FROM Table 
GROUP BY Name 
ORDER BY SUM(count) DESC

一般情况下,如果您需要帮助,可以使用此tutorial