當前位置:首頁 » 編程語言 » sql語句科目表怎麼查成績
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql語句科目表怎麼查成績

發布時間: 2022-05-24 14:09:10

『壹』 sql學生表,科目表,成績表,怎麼查每個人各科目的總分

為什麼都不喜歡給表結構
看我強大的想像能力~~
select sum(分數) as 總分,
(select 學生姓名 from 學生表 where a.學生id = 學生表.學生id),
(select 科目名稱 from 科目表 where a.科目id = 科目表.科目id),
from 成績表 a
group by a.學生id,a.科目id

『貳』 mysql:如圖:sql語句應該怎麼查其中一門科目的最高分、最低分,平均得分等

select count(if(評價="差",true, null)) as 差, count(if(評價="中等",true, null)) as 中等, count(id) as 全部, max(成績) as 最高分, min(成績) as 最低分, avg(成績) as 平均分 from 成績表 where 考試時間 = '期中考試' 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有效果是對已有數據的統計平均。

『肆』 怎麼用SQL語句查詢每個學生選修的課程名及其成績

查詢選修了全部課程的學生姓名
:student 是學生表 course 是選課表 sc 是課程表
select sname
from student
where not exists
(select *
from course
where not exists
(select *
from sc
where sno =student.sno
and cno=course.cno)

『伍』 sql語句科目表學生表和成績表的查詢

每科的總成績?查詢它干什麼?要查的話這樣查:

SELECT 科目表.KUMUID,KUMUName,SUM(CHENJI) AS SUM_CHENJI,AVG(CHENJI) AS AVG_CHENJI
FROM 科目表,成績表
WHERE 科目表.KUMUID=成績表.KUMUID
GROUP BY 科目表.KUMUID,KUMUName

由於是查每科的總成績和平均分,所以和學生沒有關系,不用關聯學生表
----------------------------------------------------------------

不過我懷疑你是不是想查每個學生的總成績和平均分,是這樣查的:

SELECT 學生表.UID,UName,SUM(CHENJI) AS SUM_CHENJI,AVG(CHENJI) AS AVG_CHENJI
FROM 學生表,成績表
WHERE 學生表.UID=成績表.UID
GROUP BY UID,UName

=========================================================
對於樓主的補充的回答:
你所要的SQL語句我已經寫了,這個查詢由於是查詢每個科目的總成績,所以不需要查詢學生的姓名,所以不應關聯學生表。只需要用成績表關聯科目表(目的是查詢出科目的名稱)。然後直接使用分組匯總(就是用 GROUP BY 子句和SUM、AVG兩個聚合函數實現的)。
分組查詢是一種最基本的查詢,現在的主流資料庫都支持它。所以每一個學習資料庫的人都應該很好的理解它。

『陸』 查詢每個學生的各科成績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)。

『柒』 簡單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

這樣行不?憑想像寫的,請參考

『捌』 如何使用sql編寫查詢語句 用於查詢學生的 各科成績

declare
@sql
varchar(8000)
select
@sql='select
a.mname
as
學生姓名'
select
@sql=@sql+',sum(case
c.fname
when
'''+fname+'''
then
b.score
else
null
end
)as
'+fname
from
f
select
@sql=@sql+'
from
member
a
left
join
score
b
on
a.mid=b.mid
left
join
f
c
on
b.fid=c.fid
group
by
a.mname'
print
@sql
exec
(@sql)
費了好勁,真麻煩,頭一次搞這個東西

『玖』 按照人名查出學生的各科成績以及總成績並按總成績排名的sql語句

按照人名查出學生的各科成績以及總成績並按總成績排名的sql語句示例如下:

selectA.name ,

(selectB.scorefromtable_scoreBwhereB.type='數學'andA.id=B.id) as數學 ,

(selectB.scorefromtable_scoreBwhereB.type='語文'andA.id=B.id) as語文,

(selectB.scorefromtable_scoreBwhereB.type='英語'andA.id=B.id)as英語,

(selectSUM(B.score)fromtable_scoreBwhereA.id=B.id)assum_score

fromtable_studentAorderbysum_scoreDESC

以上sql語句首先把學生表和成績表聯合查出每個學生的數學、語文、英語成績,然後通過selectSUM(B.score)fromtable_scoreBwhereA.id=B.id查出每個學生的總成績。

最後orderbysum_scoreDESC實現按總成績倒敘排列。


(9)sql語句科目表怎麼查成績擴展閱讀

上述sql語句重點是對as關鍵字的使用- Alias(別名),通過使用 SQL,可以為列名稱和表名稱指定別名(Alias)。

表的 SQL Alias 語法

SELECT column_name(s) FROM table_name AS alias_name;

列的 SQL Alias 語法

SELECT column_name AS alias_name FROM table_name;

Alias 實例: 使用表名稱別名

假設我們有兩個表分別是:"Persons" 和 "Proct_Orders"。我們分別為它們指定別名 "p" 和 "po"。

現在,我們希望列出 "John Adams" 的所有定單。

我們可以使用下面的 SELECT 語句:

SELECT po.OrderID, p.LastName, p.FirstName FROM Persons AS p, Proct_Orders AS poWHERE p.LastName='Adams' AND p.FirstName='John'

『拾』 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