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)。