MySQL: Count entries without grouping?

前端 未结 6 991
予麋鹿
予麋鹿 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:02

    This uses group by but gets the output in the format you want.

    SELECT Name, NG.NameCount
    FROM Names
    INNER JOIN
        (SELECT Name, Count(1) As NameCount
        FROM Names
        GROUP BY Name) NG
    ON Names.Name = NG.Name
    

提交回复
热议问题