SUM of grouped COUNT in SQL Query

前端 未结 17 1760
夕颜
夕颜 2020-12-04 08:19

I have a table with 2 fields:

ID  Name
--  -------
1   Alpha
2   Beta
3   Beta
4   Beta
5   Charlie
6   Charlie

I want to group them by name, with \'co

17条回答
  •  自闭症患者
    2020-12-04 08:57

    all of the solution here are great but not necessarily can be implemented for old mysql servers (at least at my case). so you can use sub-queries (i think it is less complicated).

     select sum(t1.cnt) from 
            (SELECT column, COUNT(column) as cnt
                FROM
                table 
                GROUP BY 
                column
                HAVING 
                COUNT(column) > 1) as t1 ;
    

提交回复
热议问题