MySQL: Count entries without grouping?

前端 未结 6 1005
予麋鹿
予麋鹿 2021-02-07 06:32

I want to pull results and count how many of each name is pulled but without grouping...

for example I want this:

John Doe 3
John Doe 3
John Doe 3
Mary J         


        
6条回答
  •  面向向阳花
    2021-02-07 07:06

    SELECT b.name, a.the_count
    FROM
      some_table b, 
      (SELECT name, COUNT(*) AS the_count
      FROM some_table
      GROUP BY name) AS a
    WHERE b.name = a.name
    

提交回复
热议问题