MySQL: Count entries without grouping?

前端 未结 6 990
予麋鹿
予麋鹿 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 06:48

    SELECT `name`,
        (
            SELECT COUNT(*)
            FROM `table` AS `alt`
            WHERE `alt`.`name` = `table`.`name`
        ) AS `num`
    FROM `table`
    

提交回复
热议问题