sql 面试题

表1:学生ID、学生姓名、性别、年级、班级;表2:学生ID、科目、成绩(分数)一年级,每一门课成绩都在90分以上,女生的人数有多少?

SELECT count(sss.stu_id)
from
(SELECT DISTINCT ss.stu_id
from 
(SELECT c_name,stu_id,grade,s1.sex
from student s1 left JOIN score s2 on s1.id = s2.stu_id
GROUP BY c_name,stu_id,grade,s1.sex HAVING grade > 10 and s1.sex = "女") as ss
GROUP BY ss.stu_id,ss.c_name HAVING count(ss.c_name)=9 ) sss --9是科目数

你可能感兴趣的:(sql,数据库)