MySQL: Group By & Count Multiple Fields

前端 未结 1 2040
一个人的身影
一个人的身影 2021-01-15 16:27

If I have a single field, say, project_id where I want to count the occurrences, I would do something like:

select project_id, count(project_id) as count fro         


        
相关标签:
1条回答
  • 2021-01-15 16:53
    select project_id, service_id, count(*) as count 
    from tbl group by project_id, service_id
    order by count(*) desc
    

    Just add service_id to your group by and select list. That should do it.

    EDIT -

    As per comment from @Rajah it seems that for your expected output, you need to use

    order by project_id asc, service_id asc
    
    0 讨论(0)
提交回复
热议问题