select
s.SId,
s.Sname,
co.CId,
co.Cname,
c.score,
b.score as bscore,(多条数据,数据展示出来才会确定,)
COUNT(DISTINCT b.score)+1 as rank 排名的关键
from sc c
LEFT JOIN sc b on c.CId = b.CId and c.score < b.score 排名的关键,自己关联自己查询,在当前条件下所有比当前分数高的个数(查询出多条数据,只有将数据展示出来才确定)
LEFT JOIN student s on s.Sid = c.Sid
LEFT JOIN course co on c.Cid = co.Cid
where c.CId = '01'
GROUP BY c.Cid,c.Sid
ORDER BY c.Cid,rank