按计数查询顺序

发布于 2024-12-28 07:58:39 字数 221 浏览 0 评论 0原文

ID 名称

  • 1 Asd
  • 2 Qwe
  • 3 Asd
  • 4 Asd
  • 5 Qwe
  • 6 Dsa

我需要一个查询按计数返回组顺序,例如;

ID 名称

  • 1 Asd
  • 2 Qwe
  • 3 Dsa

ID Name

  • 1 Asd
  • 2 Qwe
  • 3 Asd
  • 4 Asd
  • 5 Qwe
  • 6 Dsa

i need a query returns group order by count like;

ID Name

  • 1 Asd
  • 2 Qwe
  • 3 Dsa

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独闯女儿国 2025-01-04 07:58:39

试试这个可能会有帮助,

SELECT COUNT(Name) AS total, id, Name
FROM table_name
GROUP BY Name   
ORDER BY COUNT(Name) DESC;

Try this it might be helpful,

SELECT COUNT(Name) AS total, id, Name
FROM table_name
GROUP BY Name   
ORDER BY COUNT(Name) DESC;
爱你不解释 2025-01-04 07:58:39
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)

为包含名称列表的表。

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 

change this subquery

      (SELECT DISTINCT iName, COUNT(iName) AS iCount 
       FROM people 
       GROUP BY iName 
       ORDER BY iCount DESC)

to the table with the list of name.

九歌凝 2025-01-04 07:58:39

检查这个

SELECT id, Name FROM user
GROUP BY Name   
ORDER BY COUNT(Name) DESC;

Check This

SELECT id, Name FROM user
GROUP BY Name   
ORDER BY COUNT(Name) DESC;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文