SQL SUM仅返回第一条记录

时间:2017-12-17 16:49:49

标签: mysql sql

SELECT playerID, nameLast, SUM(IP), SUM(WAR)
FROM `mlb_pitchers`
WHERE (year >= '1903' and year <= '1906')
ORDER BY WAR

以上仅返回数据库中第一个投手的SUM。如何让它收集所有投手的总结?

SELECT playerID, nameLast, SUM(IP), SUM(WAR)
FROM `mlb_pitchers`
WHERE playerID = 'mathech01' and (year >= '1903' and year <= '1906') 

如果我特定于玩家ID,我会得到1903 - 1906年的总和值。

1 个答案:

答案 0 :(得分:4)

使用GROUP BY之类的:

SELECT playerID, nameLast, SUM(IP), SUM(WAR)
FROM mlb_pitchers
where year >= '1903' and year <= '1906'
GROUP BY playerID, nameLast
ORDER BY SUM(WAR) desc