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

sql中顯示後三個最低成績

發布時間: 2022-08-24 06:08:13

❶ 一個sql問題:求得一個班級中所有學生某個科目最近一次考試的成績的最低分

沒建表 你自己試試 先求出那個科目的ID,我去沒有ID,那就假定
一個學生不可能在同一時間 考相同的科目
希望你是認真的研究此問題 而不是直接拷貝我的結果糊弄老師
--先設定那個科目
declare @SubjectName varchar(50)
set @SubjectName = 'XXXX'
select a.StudentNo,b.StudentResult
from StudentNo a left join --顯示結果,沒有參加考試的顯示NULL
(select a.StudentNo,a.StudentResult from Result a inner join --關聯最後一次考試的成績
(select a.StudentNo,a.SubjectId,MAX(a.ExamDatetime) as MaxExamDatetime
from Result a --取出某個科目最後的考試時間
inner join Subject b on a.SubjectId = b.SubjectId
where SubjectName = @SubjectName
group by a.StudentNo,a.SubjectId) b
on a.StudentNo = b.StudentNo and a.SubjectId = b.SubjectId and a.ExamDatetime = b.MaxExamDatetime
) b
on a.StudentNo = b.StudentNo

❷ sql查詢成績倒數第三的信息

做是可以做出來的,只要結果的話好說:
Oracle資料庫下:

select * from(select rownum rownumNO,筆試成績,機試成績,其他信息 from stuMarks) where rownumNO=(select count(*) from stuMarks)-2

這個的話就是查出來倒數第三的成績了,注意最後一個是-2。如果你要優化的話,或者有其他需求的話給我留言,OK?

❸ 在SQL語句中怎麼查詢一個科目的最高分和最低分還有平均分

select max(科目) as '最高分',min(科目) as 最低分,round(avg(科目),2) as '平均分' from 表

round(avg(科目),2) 意思是平均分保留兩位小數,因為在多個科目中就可以出現小數

如果有一科或多科沒有成績使用avg就不正確,應該用以下語句:

select max(科目) as '最高分',min(科目) as 最低分,round(sum(科目)/科目數,2) as '平均分' from 表

因為avg有效果是對已有數據的統計平均。

❹ sql 顯示平均成績後三名的學生的學號和平均分

--取前3名
selecttop3*fromTABLEorderbyscoredesc;
--取後3名
selecttop3*fromTABLEorderbyscore;

❺ ACCESS sql 查出每個人成績最小值

可以用姓名分組求最小值,請參見下列SQL語句

selectb.*from成績表b,
(select姓名,min(成績)as最低分from成績表groupby姓名)a
wherea.姓名=b.姓名andb.成績=a.最低分;

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

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

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

select b.課程名,avg(a.分數) as 平均成績,max(a.分數) as 最高成績,min(a.分數) as 最低成績
from 成績表 a,課程表 b
where a.課程號=b.課程號
group by b.課程名

❽ sql查詢最高分和最低分

//查詢最高分
selectmax(score)fromstudent
//查詢最低分www.sz886.com
selectmin(score)fromstudent
//查詢最低分和最高分
selectmin(score)asmin_score,max(score)asmax_scorefromstudent

❾ 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

❿ sql 如何選出某一個時間段內學生的最低成績

select min(score) from tablename where time>minTime and time<maxTime //意思為查詢表tablename(表名***/*應該為學生成績表*/)中最低成績 where條件為 time>minTime and time<maxTime 這個時間段 注意定義表示 一定要有時間屬性
查看所有學生某段時間內的最低成績:
select min(score) from tableName where time>=startTime> and time<=endTime group by stuId;
http://www.w3school.com.cn/sql/sql_func_min.asp
這里有參考,這個網有多東西可以學習。