SQL Order By Count

前端 未结 8 2207
北海茫月
北海茫月 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:04

    Try :

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

    to order by count descending do

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

    This will group the results by the group column returning the group and the count and will return the order in group order

提交回复
热议问题