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
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
3. 成绩sql 查询
执行下抄面的代码:袭
select max(usrtname)as username,
max('en') as en,
sum(case item when 'en' then score else '' end) as score,
max('ma') as ma,
sum(case item when 'ma' then score else '' end) as score
from 表名
group by username
得到的结果是:
username en score ma seore
_______________________________________
kenny en 80 ma 90
mary en 70
你看满足你的要求不
4. 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 "平均成绩容"
5. 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 课程 ;
6. SQL语句如何查询成绩第二高的学生
假设学生成绩表为xscj,里面有若干个字段,其中包括具体成绩得分字段df,那么,查询版所有成权绩第二高学生的SQL语句如下:
select * from xscj where df in (
select max(df) from xscj where df not in (
select max(df) from xscj))
该语句嵌套基层,最内层的语句查询最高分,第二层的语句查询除了最高分以外后剩下的最高分(即第二高分),最外层即是查询第二高分有哪些人(可能存在多人的情况)。
7. sql通过分数查询所在等级 急急急!!!
select 员工编号,考核分数,等级=case
when 考核分数 between 90 and 100 then '优等'
when 考核分数 between 80 and 89 then '甲等'
when 考核分数 between 70 and 79 then '乙等'
还有丙丁等自己写。
8. sql语句查询横排成绩表中成绩最好的学生姓名、科目和成绩
/*
让我们假设 这个表叫ExamResults.
name - 姓名
subjects - 科目内
grades - 成绩容
*/
--then the query is as following.
select
er1.name, er1.subjects, er1.grades
from ExamResults as er1, ExamResults as er2
where er1.name = er2.name and er1.grades > er2.grades
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)。
10. 查询成绩表信息的SQL语句
select * from 成绩表