當前位置:首頁 » 編程語言 » sql平均分和最低成績
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql平均分和最低成績

發布時間: 2023-07-23 00:57:16

A. 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#

B. 1查詢成績表的總分數,平均分,最低分和最高分。用sql語句怎麼寫

1. 計算每個人的總成績並排名(要求顯示欄位:姓名,總成績)
select name,sum(cast(score as bigint)) as allscore from stuscore group by name order by allscore desc
2. 計算每個人的總成績並排名(要求顯示欄位: 學號,姓名,總成績)

select stuid,name,sum(cast(score as bigint)) as allscore from stuscore group by stuid,name order by allscore desc
3. 計算每個人單科的最高成績(要求顯示欄位: 學號,姓名,課程,最高成績)
SELECT t1.stuid,t1.name,t1.subject,t1.score from stuscore t1,(SELECT stuid,max(score) as maxscore from stuscore group by stuid) t2 where t1.stuid=t2.stuid and t1.score=t2.maxscore
4. 計算每個人的平均成績(要求顯示欄位: 學號,姓名,平均成績)
select distinct t1.stuid,t1.name,t2.avgscore from stuscore t1,(select stuid,avg(cast(score as bigint)) as avgscore from stuscore group by stuid) t2 where t1.stuid=t2.stuid

C. 怎樣編寫SQL語句求平均成績

1、打開資料庫軟體,附加資料庫,右鍵選擇新建查詢。

D. SQL語句查詢每個學生的學號、姓名、平均成績、最高成績和最低成績

select 學生表.學號,學生表.姓名,
average(成績表.成績) as 平均成績,
max(成績表.成績) as 最高成績,
min(成績表.成績) as 最低成績
from 學生表 left join 成績表 on 學生表.學號=成績表.學號
order by 學生表.學號
成績表可換成語文、數學、英語等,查詢結果就是各個學生相應課程的平均成績、歷史最高成績、歷史最低成績.

E. 1查詢成績表的總分數,平均分,最低分和最高分。用sql語句怎麼寫

---1. 計算每個人的總成績並排名(要求顯示欄位:姓名,總成績)
select name,sum(cast(score as bigint)) as allscore from stuscore group by name order by allscore desc
---2. 計算每個人的總成績並排名(要求顯示欄位: 學號,姓名,總成績)
select stuid,name,sum(cast(score as bigint)) as allscore from stuscore group by stuid,name order by allscore desc
---3. 計算每個人單科的最高成績(要求顯示欄位: 學號,姓名,課程,最高成績)
SELECT t1.stuid,t1.name,t1.subject,t1.score from stuscore t1,(SELECT stuid,max(score) as maxscore from stuscore group by stuid) t2 where t1.stuid=t2.stuid and t1.score=t2.maxscore
---4. 計算每個人的平均成績(要求顯示欄位: 學號,姓名,平均成績)
select distinct t1.stuid,t1.name,t2.avgscore from stuscore t1,(select stuid,avg(cast(score as bigint)) as avgscore from stuscore group by stuid) t2 where t1.stuid=t2.stuid
---5. 列出各門課程成績最好的學生(要求顯示欄位: 學號,姓名,科目,成績)
select t1.stuid,t1.name,t1.subject,t2.maxscore from stuscore t1,(select subject,max(score) as maxscore from stuscore group by subject) t2 where t1.subject=t2.subject and t1.score=t2.maxscore
---6. 列出各門課程成績最好的兩位學生(要求顯示欄位: 學號,姓名,科目,成績)
select distinct t1.* from stuscore t1 where t1.stuid in(select top 2 stuscore.stuid from stuscore where subject = t1.subject order by score desc)order by t1.subject
---7. 統計報表(要求顯示欄位: 學號,姓名,各科成績,總分,平均成績)
select stuid as 學號,name as 姓名,sum(case when subject='語文' then score else 0 end) as 語文,sum(case when subject='數學' then score else 0 end) as 數學,sum(case when subject='英語' then score else 0 end) as 英語,sum(cast(score as bigint)) as 總分,(sum(cast(score as bigint))/count(*)) as 平均分 from stuscore group by stuid,name order by 總分 desc
---8. 列出各門課程的平均成績(要求顯示欄位:課程,平均成績)
select subject,avg(cast(score as bigint)) as avgscore from stuscore group by subject
---9. 列出數學成績的排名(要求顯示欄位:學號,姓名,成績,排名)
select * from stuscore where subject ='數學' order by score desc
---10. 列出數學成績在2-3名的學生(要求顯示欄位:學號,姓名,科目,成績)
select t3.* from(select top 2 t2.* from (select top 3 name,subject,score,stuid from stuscore where subject='數學' order by score desc) t2 order by t2.score) t3 order by t3.score desc
---11. 求出李四的數學成績的排名
declare @tmp table(pm int,name varchar(50),score int,stuid int)
insert into @tmp select null,name,score,stuid from stuscore where subject='數學' order by score desc
declare @id int
set @id=0;
update @tmp set @id=@id+1,pm=@id
select * from @tmp where name='李四'
---12. 統計各科目及格人數
select subject,
(select count(*) from stuscore where score<60 and subject=t1.subject) as 不及格,
(select count(*) from stuscore where score between 60 and 80 and subject=t1.subject) as 良,
(select count(*) from stuscore where score >80 and subject=t1.subject) as 優
from stuscore t1 group by subject
---13.統計如下:數學:張三(50分),李四(90分),王五(90分),趙六(76分)
declare @s varchar(1000)
set @s=''
select @s =@s+','+name+'('+convert(varchar(10),score)+'分)' from stuscore where subject='數學'
set @s=stuff(@s,1,1,'')
print '數學:'+@s

F. SQL按課程統計課程的平均分,要求顯示課程名稱、平均分

SELECT 課程.課程名稱,AVG(選課.成績)AS"平均成績"

FROM 課程, 選課

where 選課.課程代碼=課程.課程代碼

GROUP BY 課程.課程名稱

SQL中在統計每門課程的平均成績、最高成績和最低成績

select b.課程zhuan名,avg(a.分數) as 平均成績shu,max(a.分數) as 最高成績,min(a.分數) as 最低成績

from 成績表 a,課程表 b

where a.課程號=b.課程號

group by b.課程名

(6)sql平均分和最低成績擴展閱讀:

由於SQL Servers資料庫管理系統具有較高的數據管理性能,因其優越的性能,應用范圍非常廣,大量應用於伺服器和客戶體系結構中。SQL Servers資料庫的性質主要由以下幾個方面體現:系統的吞吐量、響應時間以及並行處理能力, 發出請求伺服器回應的速度、還有不同屏幕之間切換的速度等等。

G. sql問題,查找每門課程選課學生,平均分,最高分,最低分 。怎麼解答啊

你好,很高興回答你的問題。
解決這個問題需要用到分組查詢和聚合函數。
sql大致如下:
select 課程,avg(分數),max(分數),min(分數) from 表 group by 課程。
其中avg是算平均分。
max是算最大分。
min是算最小分。
如果有幫助到你,請點擊採納。
我解答的大部分是軟體開發新人遇到的問題,如果有興趣可以關注我。