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