select a.id, a.name, a.score
from (select g.id,g.score,l.name, dense_rank() over(partition by l.id order by g.score desc) rk
from grade g
left join language l on g.language_id = l.id) a
where a.rk < 3
order by a.name asc, a.score desc