当前位置:   article > 正文

java面试题之sql语句_计算各科都及格学生的平均成绩

计算各科都及格学生的平均成绩

根据这一张表进行sql操作

93fe6aca9fb70e8955ca0e94c78d2d2a.png

– 分组查询总分数

select num,name,SUM(score) as scoreall from score2 GROUP BY name order by scoreall

– 计算每个人单科最高成绩

select name,MAX(score) from score2 GROUP BY name

– 计算每个人的平均成绩

select name,AVG(score) from score2 GROUP BY name

– 列出各科成绩最好的学生

select DISTINCT ‘最高分’,score2.* from score2,(select MAX(score) as score,course from score2 GROUP BY course ) b

where score2.score=b.score

6a2deeff6021a45cdfd845d98a318fb4.png

– 分组统计姓名 语文、数学、英语、总分、平均分

select name as ‘姓名’,SUM(case when course=‘语文’ then score end) as ‘语文’,SUM(case when course=‘数学’ then score end)‘数学’,

SUM(case when course=‘英语’ then score end)‘英语’,SUM(score),AVG(score) FROM score2 GROUP BY name

a03a5cf37aefa675ae6f69c0a1d34a52.png

– 列出数学成绩的排名

select name,course,score from score2 where course=‘数学’ order by score desc

fe52e60f0b4cc356bd42e57f6b223d77.png

– 统计课程和对应的优秀、及格、不及格个数

select course,(select COUNT(*) from score2 where course=t.course and score>=80)‘优秀’,

(select COUNT(*) from score2 where course=t.course and score>=60 and score<80)‘良好’,

(select COUNT(*) from score2 where course=t.course and score<60)‘不及格’

from score2 t GROUP BY course

37e399c18c022cb980ad2f8cf6edd06c.png

– 计算各科都及格的的人的平均成绩

select name,AVG(score) from score2 GROUP BY name having MIN(score)>60

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

闽ICP备14008679号