SQL Order By Count

前端 未结 8 2208
北海茫月
北海茫月 2020-12-01 02:38

If I have a table and data like this:

ID |  Name  |  Group   

1    Apple     A    

2    Boy       A

3    Cat       B

4    Dog       C

5    Elep      C

         


        
8条回答
  •  一个人的身影
    2020-12-01 03:07

    SELECT group, COUNT(*) FROM table GROUP BY group ORDER BY group
    

    or to order by the count

    SELECT group, COUNT(*) AS count FROM table GROUP BY group ORDER BY count DESC
    

提交回复
热议问题