sql查询成绩
1. 简单SQL语句,查询成绩
select * from xs
inner join
(
select km,max(fs) as fs from xs group by km
)w
on xs.km = w.km and xs.fs = w.fs
这样行复不?制凭想象写的,请参考
2. sql查询问题 查询成绩分布情况
整到一张表:
select 课程,
sum(人数*case 类别 when '优秀' then 1 else 0 end) 优秀人数,sum(人数*case 类别 when '优秀' then 1 else 0 end)/sum(人数)*100 优秀百分比,
sum(人数*case 类别 when '良好' then 1 else 0 end) 良好人数,sum(人数*case 类别 when '良好' then 1 else 0 end)/sum(人数)*100 良好百分比,
sum(人数*case 类别 when '中等' then 1 else 0 end) 中等人数,sum(人数*case 类别 when '中等' then 1 else 0 end)/sum(人数)*100 中等百分比,
sum(人数*case 类别 when '及格' then 1 else 0 end) 及格人数,sum(人数*case 类别 when '及格' then 1 else 0 end)/sum(人数)*100 及格百分比,
sum(人数*case 类别 when '缺考' then 1 else 0 end) 缺考人数,
sum(人数*case 类别 when '不及格' then 1 else 0 end) 不及格人数,
sum(人数*case when 类别 in('优秀','良好','中等','及格') then 1 else 0 end) 及格人数
from (select 课程,count(*) as 人数,‘优秀’ as 类别
from 成绩
where grade>=90
group by 课程
union
select 课程,count(*) as 人数,‘良好’ as 类别
from 成绩
where grade>80 and grade<90
group by 课程
union
select 课程,count(*) as 人数,‘中等' as 类别
from 成绩
where grade>70 and grade<80
group by 课程
union
select 课程,count(*) as 人数,‘及格’ as 类别
from 成绩
where grade>=60 and grade<70
group by 课程
union
select 课程,count(*) as 人数,‘不及格’ as 类别
from 成绩
where grade<60
group by 课程
union
select 课程,count(*) as 人数,‘缺考' as 类别
from 成绩
where grade is null
group by 课程)
group by 课程 ;
3. SQL查询学生成绩
select a.studentId,a.name,a.sex,c.cid,b.cname,c.score
into TableA
from Student a, Course b, Grade c
where a.studentId=c.studentId and c.cid=b.cid
select a.studentId,a.name,a.sex,
sum(case cname when "语文" then score else 0 end) as 语文,
sum(case cname when "数学" then score else 0 end) as 数学,
sum(case cname when "英语" then score else 0 end) as 英语,
sum(case cname when "哲学内" then score else 0 end) as 哲学,
sum(score)*1.0/4 as "平均成绩容"
4. SQL查询单科成绩最高的同学
SELECT child.abc,child.cource,a.name
FROM (select max(b.point) as abc,c.cource from `student` as a join `achievement` as b join `course` as c on a.sex = 1 and b.sid=a.id and b.cid=c.id group by c.cource) as child
join `student` as a join `achievement` as b join `course` as c on a.sex = 1 and b.sid=a.id and b.cid=c.id where child.abc=b.point and child.cource=c.cource
很繁琐,子查询和查询的都是同一个表同一个条件,答案包对专
不要姓名要学属号的话就把名字换一下
原理
子查询出最高分和科目,再用父查询把(同条件下)把最高分和科目配对
5. SQL语句如何查询成绩第二高的学生
假设学生成绩表为xscj,里面有若干个字段,其中包括具体成绩得分字段df,那么,查询版所有成权绩第二高学生的SQL语句如下:
select * from xscj where df in (
select max(df) from xscj where df not in (
select max(df) from xscj))
该语句嵌套基层,最内层的语句查询最高分,第二层的语句查询除了最高分以外后剩下的最高分(即第二高分),最外层即是查询第二高分有哪些人(可能存在多人的情况)。
6. SQL查询平均成绩
select
classid
as
班级编号,max(case
when
sex=0
then
avg_grade
else
0
end)
as
男生平均成绩版权,
max(case
when
sex=1
then
avg_grade
else
0
end)
as
女生平均成绩
from
(select
classid,sex,avg(grade)
as
avg_grade
from
student
a
inner
join
sc
b
on
a.id=b.id
)
t
group
by
classid
7. 查询成绩的SQL语句是什么
不知道你的表结构是什么啊?
例如表的字段有姓名、课程、成绩的话专
每人的总成绩:SELECT 姓名,SUM(成绩) FROM 表名属 GROUP BY 姓名
每人的平均成绩:SELECT 姓名,SUM(成绩)/COUNT(*) FROM 表名 GROUP BY 姓名
每人的课程门数:SELECT 姓名,COUNT(*) FROM 表名 GROUP BY 姓名
8. 查询成绩表信息的SQL语句
select * from 成绩表
9. 查询每个学生的各科成绩sql语句
1、查询每个学生的各科成绩sql语句:
select a.studentid,a.name,a.sex,v1.score as '语文',v2.score as '数学', v3.score as '英语',v4.score
as ‘哲学’, (v1.score+v2.score+v3.score+v4.score)/4 as ‘平均成绩’ from Stuednt a
left join
(select studentid,score from grade where cid=(select cid from course where cname='语文'))as v1
on a.studentid=v1.studentid
left join
(select studentid,score from grade where cid=(select cid from course where cname='数学'))as v2
on a.studentid=v2.studentid
left join
(select studentid,score from grade where cid=(select cid from course where cname='英语'))as v3
on a.studentid=v3.studentid
left join
(select studentid,score from grade where cid=(select cid from course where cname='哲学'))as v4
on a.studentid=v4.studentid
order by a.studentid
2、sql数据库介绍:
(1)SQL是Structured Query Language(结构化查询语言)的缩写。SQL是专为数据库而建立的操作命令集,是一种功能齐全的数据库语言。在使用它时,只需要发出"做什么"的命令,"怎么做"是不用使用者考虑的。
(2)SQL功能强大、简单易学、使用方便,已经成为了数据库操作的基础,并且现在几乎所有的数据库均支持SQL。
(3)SQL数据库的数据体系结构基本上是三级结构,但使用术语与传统关系模型术语不同。
(4)在SQL中,关系模式(模式)称为"基本表"(base table);存储模式(内模式)称为"存储文件"(stored file);子模式(外模式)称为"视图"(view);元组称为"行"(row);属性称为"列"(column)。