MySQL: Count entries without grouping?

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

    Maybe count over partition?

    select 
         p.name,
         count(p.name) over (partition by p.name) as counted
    from some_table as p
    order by counted desc
    

提交回复
热议问题