select t.id,(
select count(s.exam_score_zf)+1
from school_exam_score s
where s.exam_score_zf>t.exam_score_zf and s.school_exam=:examid
<#if school_klass ?exists && school_klass ?length gt 0>
and s.school_klass =: school_klass
</#if>
) rank
from school_exam_score t
where t.school_exam=:examid
<#if school_klass ?exists && school_klass ?length gt 0>
and t.school_klass =: school_klass
</#if>
ORDER BY t.exam_score_zf DESC;