当前位置:   article > 正文

数据库(MYSQL)综合演练_数据库综合csdn

数据库综合csdn

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

select st.*,sc.s_Score as '语文' ,sc2.s_Score '数学' 
from Student st
left join Score sc on sc.s_id=st.s_id and sc.c_id='01' 
left join Score sc2 on sc2.s_id=st.s_id and sc2.c_id='02'  
where sc.s_Score>sc2.s_Score;
  • 1
  • 2
  • 3
  • 4
  • 5

请添加图片描述

2、查询"01"课程比"02"课程成绩低的学生的信息及课程分数

select st.*,sc.s_Score '语文',sc2.s_Score '数学' 
from Student st
left join Score sc on sc.s_id=st.s_id and sc.c_id='01'
left join Score sc2 on sc2.s_id=st.s_id and sc2.c_id='02'
where sc.s_Score<sc2.s_Score;
  • 1
  • 2
  • 3
  • 4
  • 5

请添加图片描述

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

select st.s_id,st.s_name,ROUND(AVG(sc.s_Score),2) cjScore 
from Student st
left join Score sc on sc.s_id=st.s_id
group by st.s_id having AVG(sc.s_Score)>=60;
  • 1
  • 2
  • 3
  • 4

请添加图片描述

4、查询平均成绩小于60分的同学的学生编号和学生姓名和平均成绩(包括有成绩的和无成绩的)

select st.s_id,st.s_name,(case when ROUND(AVG(sc.s_Score),2) is null then 0 else ROUND(AVG(sc.s_Score)) end ) cjScore 
from Student st
left join Score sc on sc.s_id=st.s_id
group by st.s_id having AVG(sc.s_Score)<60 or AVG(sc.s_Score) is NULL;
  • 1
  • 2
  • 3
  • 4

请添加图片描述

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

select st.s_id,st.s_name,count(sc.c_id) '选课总数',(case when sum(sc.s_Score) is null or sum(sc.s_Score)='' then 0 else sum(sc.s_Score) end) '总成绩'
from Student st
left outer join Score sc on st.s_id=sc.s_id
group by st.s_id;
  • 1
  • 2
  • 3
  • 4

请添加图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/771191
推荐阅读
相关标签
  

闽ICP备14008679号