『壹』 查詢每個學生的各科成績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的查詢語句列出某同學所有課程的課程名和成績啊,並按成績從低到高排序啊
1、打開Microsoft SQL Server 2012,選中需要查詢所有表的資料庫。
『叄』 查詢學生總成績的sql語句
select 學生.學號 as 姓名, sum(成績.分數) as 總分
from 學生
left join 成績 on 成績.學號=學生.學號
group by 學生.學號
sql語句
更新:update table1 set field1=value1 where 范圍
查找:select * from table1 where field1 like '%value1%' (所有包含'value1'這個模式的字元串)
排序:select * from table1 order by field1,field2 [desc]
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1[separator]
『肆』 若學生表中存儲了學號、姓名、成績等欄位,則「查詢所有學生的姓名和成績」的SQL語句是__________。
假設學生表名稱為student,姓名欄位名稱是name,成績的欄位名稱是score。
那麼「查詢所有學生的姓名和成績」的SQL語句如下:
select student.name,student.score from student;
下面我們在SQL練習網站上測試一下我們的結果,首先進入測試網站SQL Fiddle
然後新建SQL表,最後寫入執行語句。
(4)sql查詢一個學生的所有成績擴展閱讀:
SQL SELECT 語法
SELECT 列名稱 FROM 表名稱
以及:SELECT * FROM 表名稱
注釋:SQL 語句對大小寫不敏感。SELECT 等效於 select。
SQL SELECT 實例
如需獲取名為 "LastName" 和 "FirstName" 的列的內容(從名為 "Persons" 的資料庫表),請使用類似這樣的 SELECT 語句:
SELECT LastName,FirstName FROM Persons
『伍』 SQL求每個學生平均成績
selects,學號,s,姓名,c,課程名,t,平均成績
fromstudentass
leftjion
(
selectavg(成績)as平均成績,學號
fromscgroupby學號
)astont,學號=s,學號
leftjoinsconsc。學號=s,學號
leftjoincourseasconc。課程號=sc,課程號
功能:
SQL具有數據定義、數據操縱和數據控制的功能。
1、SQL數據定義功能:能夠定義資料庫的三級模式結構,即外模式、全局模式和內模式結構。在SQL中,外模式又叫做視圖(View),全局模式簡稱模式(Schema),內模式由系統根據資料庫模式自動實現,一般無需用戶過問。
2、SQL數據操縱功能:包括對基本表和視圖的數據插入、刪除和修改,特別是具有很強的數據查詢功能。
以上內容參考:網路-結構化查詢語言
『陸』 sql:查詢所有學生的學號、姓名、入學成績、選課門數和平均分。結果要求顯示如下
SQL語句如下:
select student.sno 學號,sname 姓名,sgrade 入學成績,count(cno)選課門數,avg(grade)平均分
from student,score
where student.sno=score.sno
group by student.sno,sname,sgrade;
其中sno、sname、sgrade、cno、grade分別為:學號、姓名、入學成績、課程號、成績。以上SQL語句在Microsoft SQL Server 2005下測試通過。
『柒』 查詢每位同學的課程門數、總成績、平均成績」的SQL語句是什麼
SQL語句如下:
SELECT 學號, Count(課程編號) AS 課程總數, Sum(成績) AS 總分數, Avg(成績) AS 平均分
FROM 成績表
GROUP BY 學號;
SQL常用操作語句如下:
選擇:select * from table1 where 范圍
插入:insert into table1(field1,field2) values(value1,value2)
刪除:delete from table1 where 范圍
更新:update table1 set field1=value1 where 范圍
查找:select * from table1 where field1 like 』%value1%』
排序:select * from table1 order by field1,field2 [desc]
總數:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
『捌』 SQL查詢一位學生每門課程成績和總成績能一起查詢嗎
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'