码迷,mamicode.com
首页 > 数据库 > 详细

sql四十题

时间:2018-06-21 13:52:47      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:avg   大于   student   个数   函数   总成绩   span   gen   core   

所以大于六十分的
SELECT * from score where num > 60;

 

所有老师以及所教课程

select teacher.tname, course.cname from course
left join teacher on course.teacher_id = teacher.tid;

 

男生个数以及女生个数

select gender,count(gender) from student group by gender;

 

临时表-在内存中临时存在

select sid from (select * from score where num > 60)as B;

 

查询生物比物理课成绩高的所有学生学号

 

查询平均成绩大于60的同学的学号和平均成绩

select student_id,avg(num) from score group by student_id having avg(num) > 60;

 

查询平均成绩大于60的同学的学号和平均成绩和姓名

select student.sname,b.student_id,b.ccc from (select student_id,avg(num) as ccc from score group by student_id having avg(num) > 60) as b
left join student on student.sid = b.student_id; 注意聚合函数

 

查询所有同学的学号,姓名,选课数,总成绩;

select student_id,student.sname,count(course_id),sum(num) from score left join student on score.student_id = student.sid
group by student_id;

sql四十题

标签:avg   大于   student   个数   函数   总成绩   span   gen   core   

原文地址:https://www.cnblogs.com/kateli/p/9208252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!