存在班级表(班级,学生编号)和学生信息表(学生编号,学生姓名,学历)用SQL语句查询每个班级学历为本科的学生人数,并按照人数排序
第1个回答 2015-11-11
table: class
class_id
stu_no
table: student
stu_no
stu_name
stu_edu
select class.class_id,count(student.stu_no)
from class left outer join student on class.stu_no=student.stu_no
where student.stu_edu='本科'
group by class.class_id
order by count(student.stu_no)追问
class_id
stu_no
table: student
stu_no
stu_name
stu_edu
select class.class_id,count(student.stu_no)
from class left outer join student on class.stu_no=student.stu_no
where student.stu_edu='本科'
group by class.class_id
order by count(student.stu_no)追问
能解释一下这个SQL语句吗
追答以class为主表右连接student找出每个班级的所有学生,加上where student.stu_edu='本科'即查找出学历为本科的学生,最后以class.class_id 分组查找出每个班级的人数,即 count(student.stu_no)
有不明白的欢迎追问
明白了,谢谢
本回答被提问者和网友采纳