MySQL - 根据大多数事件选择人名

RAN*_*GER 1 mysql

鉴于:

表叫namesid,firstlast领域.

你怎么会被发现发生的前5名最受欢迎的人时,firstlast是分开的领域?这是我现在的非工作代码......

`SELECT *, COUNT(first) AS occurrences FROM `names` GROUP BY first ORDER BY occurrences DESC LIMIT 5`
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激!

Gal*_*alz 10

对于前5名,请尝试:

SELECT first, COUNT(*) AS occurrences 
FROM names
GROUP BY first 
ORDER BY occurrences DESC 
LIMIT 5
Run Code Online (Sandbox Code Playgroud)

对于前5名,请尝试:

SELECT first, last, COUNT(*) AS occurrences 
FROM names
GROUP BY first, last
ORDER BY occurrences DESC 
LIMIT 5
Run Code Online (Sandbox Code Playgroud)