存在班级表(班级,学生编号)和学生信息表(学生编号,学生姓名,学历)用SQL语句查询每个班级学历为

存在班级表(班级,学生编号)和学生信息表(学生编号,学生姓名,学历)用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)追问

能解释一下这个SQL语句吗

追答

以class为主表右连接student找出每个班级的所有学生,加上where student.stu_edu='本科'即查找出学历为本科的学生,最后以class.class_id 分组查找出每个班级的人数,即 count(student.stu_no)

有不明白的欢迎追问

追问

明白了,谢谢

本回答被提问者和网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网