1.查询(没有学全所选)课程的信息
select s1.sid,s1.sname,c.cname from student s1,score s2,course c where s1.sid=s2.student_id
and s2.course_id=c.cid
2.查询至少有一门课与学号为"01"的同学所学相同的同学的信息
select * from student where sid in
(select DISTINCT student_id from score where student_id!=1 and course_id in
(select course_id from score where student_id=1))
3.查询和"01"号的同学学习的课程完全相同的其他同学的信息
select DISTINCT s1.sid,s1.sname from student s1
right join score s2 on s1.sid=s2.student_id
where s2.student_id in (select student_id from score
where student_id!=1 and course_id in
(select course_id from score where student_id=1))
4.查询没学过"张三"老师授课的同学的信息
select * from student where sid in
(select student_id from score where course_id in
(select cid from course where teacher_id in
(select tid from teacher where tname!=‘张三’)))
5.查询学过编号为"01"并且也学过编号为"02"的课程的同学的信息
select * from student where sid in
(select student_id from score where course_id=2 and student_id in
(select student_id from score where course_id=1))
6.查询两门及其以上不及格课程的同学的学号,姓名及其平均成绩
select s1.sid 学号,s1.sname 姓名,avg(s2.number) 平均分,count() from student s1,score s2 where s1.sid=s2.student_id and s2.number<60 group by s1.sid having count()>1
7.按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩
select s1.sid,s1.sname,c.cname,avg(s2.number) from student s1,score s2,course c where s1.sid=s2.student_id and s2.course_id=c.cid group by c.cname order by avg(s2.number) desc
8.查询所有课程的成绩第2名到第3名的学生信息及该课程成绩
select s1.sname,c.cname,s2.number from student s1,score s2,course c where s1.sid=s2.student_id and s2.course_id=c.cid group by c.cname order by s2.number desc limit 1,2
9.查询出只有两门课程的全部学生的学号和姓名
select s1.sid 学号,s1.sname 姓名,count() 课程总数 from student s1,score s2 where s1.sid=s2.student_id group by s1.sid having count()=2
10.查询每个班上男生、女生总人数
select c.caption 班级名称,s.gender 性别,count(*) 总计 from class c,student s where c.cid=s.class_id group by c.cid