您正在下降,最大和筑巢正确的路线,我稍微修改给出here答案:
select t1.nick, t1.character, t1.count
from (
select nick, character, count(*) as played
from competitor
group by nick, character
) t1
inner join
(
select nick, max(played) max_count
from
(
select nick, character, count(*) as played
from competitor
group by nick, character
)
group by nick
) t2
on t1.nick = t2.nick
and t1.count = t2.max_count
这可能是更容易,如果你创建了基本查询视图阅读:
查看名为PlayerCount:
select nick, character, count(*) as played
from competitor
group by nick, character
和SQL查询现在是:
select t1.nick, t1.character, t1.count
from PlayerCount t1
inner join
(
select nick, max(played) max_count
from PlayerCount
group by nick
) t2
on t1.nick = t2.nick
and t1.count = t2.max_count
非常感谢。这工作完美! 我甚至不知道** WITH **语句。 –
下来的选民照顾解释? – CFreitas