select t.*,sc.c_id cid2 from (select* from student , (select c_id from score where s_id ='01') t) t leftjoin score sc on t.s_id = sc.s_id and t.c_id = sc.c_id union select t.*,sc.c_id cid2 from (select* from student , (select c_id from score where s_id ='01') t) t rightjoin score sc on t.s_id = sc.s_id and t.c_id = sc.c_id
select* from student where s_id notin (select s_id from (select t.*, sc.c_id cid2 from (select* from student , (select c_id from score where s_id ='01') t) t leftjoin score sc on t.s_id = sc.s_id and t.c_id = sc.c_id union select t.*, sc.c_id cid2 from (select* from student , (select c_id from score where s_id ='01') t) t rightjoin score sc on t.s_id = sc.s_id and t.c_id = sc.c_id) tt where cid2 isnull groupby s_id) and s_id !='01'
查询两门及其以上不及格课程的同学的学号,姓名及其平均成绩
1 2 3 4 5 6 7
select stu.s_id,stu.s_name, ifnull(avg(score.s_score),0) from student stu leftjoin score on stu.s_id = score.s_id groupby stu.s_id havingsum(casewhen score.s_score>=60then0else1end) >=2