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

mysql练习题进阶版

时间:2018-08-16 19:43:38      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:_id   等于   成绩   select   编号   信息   student   mysql   col   

student表

1 查询"01"课程比"02"课程成绩高的学生的信息及课程分数  

select student.*,s_score from student,score where c_id = 01 and score.s_id = student.s_id and score.s_id in
(select s1.s_id from score s1,score s2 where s1.c_id = 01 and s2.c_id = 02 and s1.s_score >s2.s_score and s1.s_id = s2.s_id)

2 查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩

select sc.s_id,st.s_name,avg(s_score) from score sc left join student st on sc.s_id = st.s_id group by sc.s_id having avg(s_score)>60 

3 查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩

select st.s_id,s_name,count(c_id) sum_course,sum(s_score) sum_score from student st 
left join score sc on sc.s_id = st.s_id group by st.s_id 

 

mysql练习题进阶版

标签:_id   等于   成绩   select   编号   信息   student   mysql   col   

原文地址:https://www.cnblogs.com/islvgb/p/9488917.html

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