这工作:
SELECT a.year, a.name, a.runs
from players a JOIN
(SELECT year, max(runs) runs FROM players GROUP BY year
) b
ON (a.year = b.year AND a.runs = b.runs);
这不起作用:
select a.name,b.year,b.run
from players a join
(select year, max(runs) as run, name from players group by year
) b
on a.year = b.year AND a.runs = b.run;
有人可以帮我理解这个吗?
答案 0 :(得分:0)
第二个加入查询未正确分组
(select year, max(runs) as run, name from players group by year
) b
因为你也选择了你应该按名称分组的名称
(select year, max(runs) as run, name from players group by year, name
) b
但这会给你不同的结果