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是算最小分。
如果有帮助到你,请点击采纳。
我解答的大部分是软件开发新人遇到的问题,如果有兴趣可以关注我。