Query to rank rows in groups

前端 未结 3 872
既然无缘
既然无缘 2021-01-20 10:57

I\'m using Apache Derby 10.10.

I have a list of participants and would like to calculate their rank in their country, like this:

|        Country |           


        
3条回答
  •  無奈伤痛
    2021-01-20 11:53

    all you need to add is a partition by country and that should give you what you need.

    SELECT
    Country.name,
    Participant.name,
    Participant.points,
    ROW_NUMBER() OVER(PARTITION BY country order by Country.name, Participant.points) as country_rank
    from Country
    join Team
      on Country.id = Team.country_id
    join Participant
      on Team.id = Participant.team_id;
    

提交回复
热议问题