① sql语句查询成绩最高的学生
select * from 学生表 where 学生id in (select 学生id from 分数表 where 分数值 = (select Max(分数字段) from 分数表)),这样查询即可。
② 请问SQL 查询出成绩最高分
请问SQL 查询出成绩最高分
select 姓名,课程名,成绩 from tablename where 成绩=(select max(成绩) from tablename)
③ 用SQL选出每个人成绩的最高纪录
查询每个人最高成绩SQL:
第一种:先使用group by和max得到最高分数和学科,然后再查询一下score表,找到学科和分数都相同的记录
select b.* from (select max(score) t,course from score group by course) a,score b where a.t=b.score and a.course=b.course
第二种:先得到相同学科的最高分数,再查询score表,找到最高分数的记录select * from score a where score=(select max(score) from score where course=a.course)
第三种:score表中,当学科一样的时候,不存在一条记录的分数小于其它记录的分数select * from score a where not exists(select * from score where a.course=course and a.score<score)
④ sql中,表table三个字段(编号,学号,成绩),每个学生考了多次,我怎么找出每名学生的最高分,写sql语句
select 学号, 最高分=max(成绩)
from table
group by 学号
先按学号对记录进行分组,使每个学生的多条记录在一组,然后求每一组中成绩的最大值即可。
⑤ 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求各科成绩最高分
可以使用MAX函数:求最大值
SELECT 科目,MAX(分数)
FROM 表名
GROUP BY 科目
⑦ 怎么用SQL语句,查询考试年份为2004年的外语考试的最高分、最低分、平均分
select max(分数),min(分数),avg(分数) from 考试表 where year(考试时间)=2004 and 科目='外语'
⑧ 在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有效果是对已有数据的统计平均。
⑨ 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