.
.
求出各科成绩前三名的学生和成绩,与相应的课程。
正确的解法一:
select a.*
from score as a
left join score as b
on (a.sourceid = b.sourceid) and (a.score < b.score)
group by a.sourceid, a.userid, a.score
having count(a.userid) < 3
order by a.sourceid, a.score desc
正确的解法二:
select * from score as a where
(select count(*) from score as b where a.sourceid = b.sourceid and a.score < b.score) < 3