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