查找表的最常见值

时间:2013-11-24 15:08:14

标签: mysql sql

如何找到lasthit或mostdamage的表player_frags中最常见的值,并按asc命令?

SELECT DISTINCT(name) FROM players p 
INNER JOIN player_frags pf ON pf.lasthit = p.name 
OR pf.mostdamage = p.name

2 个答案:

答案 0 :(得分:2)

SELECT name FROM players p 
INNER JOIN player_frags pf ON pf.lasthit = p.name 
OR pf.mostdamage = p.name GROUP BY name Order By COUNT(*) DESC

您可以在最后添加LIMIT 1以获得最常见的名称。

SQL Fiddle

答案 1 :(得分:1)

我认为您没有尝试过,这看起来与您在发送的其他问题中发布的其他SQL完全相同

无论如何,这将返回名称与出现的频率:

SELECT COUNT(*) AS Freq, name
FROM players
GROUP BY players.name
ORDER BY COUNT(*)