score:1

Accepted answer

Use a row limiting clause:

select 
    concat(strvoornaam, strtussenvoegsel, ' ',  strachternaam) as naam, 
    sum(cast(pu.strscore as int)) as score
from tblpunten pu
join tblpuntencoureur pc on pc.puntenid = pu.id
join tblpersoon pe on pe.id = pc.persoonid
join tblseizoen se on se.id = pc.seizoenid
where pu.id not between 12 and 19 and se.intjaartal = 2019 
group by strvoornaam, strtussenvoegsel, strachternaam, pe.strachternaam
order by score desc
offset 6 rows fetch next 1 row only

This gives you the seventh row in the resultset.

Side notes:

  • table aliases help keeping the query concise and easier to write
  • you should be qualifying all columns that come into play in the query

On the other hand, if you are trying to get the rank of a specific person, then that's different. You can use rank() instead:

select *
from (
    select 
        concat(strvoornaam, strtussenvoegsel, ' ',  strachternaam) as naam, 
        sum(cast(pu.strscore as int)) as score,
        rank() over(order by sum(cast(pu.strscore as int)) desc) rn
    from tblpunten pu
    join tblpuntencoureur pc on pc.puntenid = pu.id
    join tblpersoon pe on pe.id = pc.persoonid
    join tblseizoen se on se.id = pc.seizoenid
    where pu.id not between 12 and 19 and se.intjaartal = 2019 
    group by strvoornaam, strtussenvoegsel, strachternaam, pe.strachternaam
) t
where naam = 'Pierre Gasly'

More questions

More questions with similar tag