SELECT a.schyear '考試學年',
b.timeseq '測考代號',
a.classlvl '級別',
c.ch_des '科目(中文)',
b.omclasslvl '科目級名次',
a.classcode '班別',
a.chname '中文姓名',
a.enname 'English Name',
b.sysscore '科目分數'
from tb_asr_subjassessdata b left outer join
tb_hse_common c on b.suid=c.suid and b.subjcode=c.code_id and c.tb_id='sbj' left outer join
vw_stu_lateststudent a on b.suid=a.suid and b.stuid=a.stuid and b.schyear=a.schyear
where
b.schyear=? and b.timeseq=? and
b.omclasslvl >
(select floor(max(x.omclasslvl) * 0.9) from tb_asr_subjassessdata x
where b.SUID = x.suid and b.SCHYEAR = x.schyear and b.SCHLEVEL = x.schlevel and b.SCHSESSION = x.schsession and b.CLASSLEVEL = x.classlevel and b.TIMESEQ = x.timeseq and
b.MOI = x.moi and b.SUBJCODE in ('080','165','280','205')) order by a.classlvl, c.ch_des, b.omclasslvl
0.9 代表「取後 10%(top 10% / 前 10%)」的門檻(用名次最大值 * 90% 當 cutoff)。
如果你要改成 5%(也就是「取後 5%/前 5%」的門檻),把 0.9 改成 0.95 即可: