ID名称
我需要一个查询按计数返回组顺序;
ID名称
答案 0 :(得分:2)
试试这可能会有帮助,
SELECT COUNT(Name) AS total, id, Name
FROM table_name
GROUP BY Name
ORDER BY COUNT(Name) DESC;
答案 1 :(得分:1)
SELECT @rownum:=@rownum+1 AS ID,
NameList.iName
FROM
(SELECT DISTINCT iName, COUNT(iName) AS iCount
FROM people
GROUP BY iName
ORDER BY iCount DESC) NameList,
(SELECT @rownum:=0) r
更改此子查询
(SELECT DISTINCT iName, COUNT(iName) AS iCount
FROM people
GROUP BY iName
ORDER BY iCount DESC)
到包含名称列表的表格。
答案 2 :(得分:0)
检查此
SELECT id, Name FROM user
GROUP BY Name
ORDER BY COUNT(Name) DESC;