MYSQL有一个select问题不知道有人会写不? 求表中学生 课程1 成绩大于 课程2 的学号

MYSQL有一个select问题不知道有人会写不? 求表中学生 课程1 成绩大于 课程2 的学号

问题描述:

图片说明

select t1.sid from sc t1, sc t2 where t1.cid=1 and t2.cid=2 and t1.sid=t2.sid and t1.score < t2.score
方法很多,看你喜欢用那种

select sid
from (
    select sid, 
        max(case  when cid=1 then score end) as c1,
        max(case  when cid=2 then score end) as c2
    from sc
    group by sid
) t where t.c2>t.c1