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年的总和值。
答案 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