日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql查找最高分最低分_sql查询最高分、最低分和平均分语句

發布時間:2023/12/4 数据库 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql查找最高分最低分_sql查询最高分、最低分和平均分语句 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

sql 查詢最高分、最低分和平均分語句

//我們要用就以學生成績為實例吧

/*

結構

學生表

Student(S#,Sname,Sage,Ssex) --S# 學生編號,Sname 學生姓名,Sage 出生年月,Ssex 學生性別

--2.課程表

Course(C#,Cname,T#) --C# --課程編號,Cname 課程名稱,T# 教師編號

*/

查詢各科成績最高分、最低分和平均分:以如下形式顯示:課程ID,課程name,最高分,最低分,平均分,及格率,中等率,優良率,優秀率

--及格為>=60,中等為:70-80,優良為:80-90,優秀為:>=90

--方法1

select m.C# [課程編號], m.Cname [課程名稱],

max(n.score) [最高分],

min(n.score) [最低分],

cast(avg(n.score) as decimal(18,2)) [平均分],

cast((select count(1) from SC where C# = m.C# and score >= 60)*100.0 / (select count(1) from SC where C# = m.C#) as decimal(18,2)) [及格率(%)],

cast((select count(1) from SC where C# = m.C# and score >= 70 and score < 80 )*100.0 / (select count(1) from SC where C# = m.C#) as decimal(18,2)) [中等率(%)],

cast((select count(1) from SC where C# = m.C# and score >= 80 and score < 90 )*100.0 / (select count(1) from SC where C# = m.C#) as decimal(18,2)) [優良率(%)],

cast((select count(1) from SC where C# = m.C# and score >= 90)*100.0 / (select count(1) from SC where C# = m.C#) as decimal(18,2)) [優秀率(%)]

from Course m , SC n

where m.C# = n.C#

group by m.C# , m.Cname

order by m.C#

--方法2

select m.C# [課程編號], m.Cname [課程名稱],

(select max(score) from SC where C# = m.C#) [最高分],

(select min(score) from SC where C# = m.C#) [最低分],

(select cast(avg(score) as decimal(18,2)) from SC where C# = m.C#) [平均分],

cast((select count(1) from SC where C# = m.C# and score >= 60)*100.0 / (select count(1) from SC where C# = m.C#) as decimal(18,2)) [及格率(%)],

cast((select count(1) from SC where C# = m.C# and score >= 70 and score < 80 )*100.0 / (select count(1) from SC where C# = m.C#) as decimal(18,2)) [中等率(%)],

cast((select count(1) from SC where C# = m.C# and score >= 80 and score < 90 )*100.0 / (select count(1) from SC where C# = m.C#) as decimal(18,2)) [優良率(%)],

cast((select count(1) from SC where C# = m.C# and score >= 90)*100.0 / (select count(1) from SC where C# = m.C#) as decimal(18,2)) [優秀率(%)]

from Course m

order by m.C#

本條技術文章來源于互聯網,如果無意侵犯您的權益請點擊此處反饋版權投訴

本文系統來源:php中文網

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的mysql查找最高分最低分_sql查询最高分、最低分和平均分语句的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。