1.有如下三张表?
学生表student(s_id, name, sex, score)
班级表class(c_id, c_name)
学生班级表 student_class(s_id,c_id)
(1)查询一班得分在80分以上或者等于60,61,62的学生。
(2)査询所有班级的名称,和所有版中女生人数和女生的平均分。
答案:
代码语言:javascript复制(1)SELECT s.s_id,s.name,s.score,sc.c_id,c.c_name from student s LEFT JOIN student_class sc on s.s_id = sc.s_id LEFT JOIN class c on sc.c_id=c.c_id where (s.score>80 or s.score in(60,61,62)) and c.c_name='一班';
(2)SELECT sc.s_id,c.c_name,COUNT(s.sex),AVG(s.score) from student_class sc LEFT JOIN class c on sc.c_id=c.c_id LEFT JOIN student s on sc.s_id = s.s_id where s.sex='女' group BY c.c_name ORDER BY c.c_id asc;
2.用一条 SQL语句查询出每门课都大于 80 分的学生姓名?
答案:
代码语言:javascript复制select name from student where name not in (select name from student where fenshu <=80);