⑴ 如何用sql語句查出學生表成績小於60為不及格60-80為良好80-90為優秀
select name,case when 成績<60 then 不及格 when 成績>=60 and 成績<80 then 良好 when 成績>=0 and 成績<90 then 優秀 end as 成績情況 ,from 表名。
注意,在輸入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實現按總成績倒敘排列。
(2)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'
⑶ 查詢學生總成績的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語句查將成績小於60分的計算機專業學生的成績設置為0
1、首先在sql軟體附加有成績表的資料庫,然後右鍵新建查詢。
⑸ 簡單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求總分及平均值
SQL求總分及平均值的方法。
如下參考:
1.打開資料庫軟體,添加資料庫,右鍵點擊並選擇新查詢。
⑺ 查詢每個學生的各科成績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資料庫怎麼創建查詢總分
這里分享下sql資料庫創建查詢總分的方法。
設備:聯想電腦
系統:win8
軟體:mysql資料庫6.3
1、首先新建一個test資料庫,在資料庫中創建一個data數據表,在表內插入四條測試數據。
⑼ sql查詢問題 查詢成績分布情況
呵呵,你這是一堆的問題呀:
優秀、良好……各級別的(人數):
首先,假設你的分數是 百分制,優秀即高於85分等。。。。
因此:
select 課程,count(*) as 人數,『優秀』 as 類別
from 成績
where 分數>85
group by 課程
union
select 課程,count(*) as 人數,『良好』 as 類別
from 成績
where 分數>70 and 分數<=85
group by 課程
union
select 課程,count(*) as 人數,『及格』 as 類別
from 成績
where 分數>60 and 分數<=70
group by 課程
分布情況及百分比:
得根據上面的結果來再計算。
先弄個總人數的視圖:select count(*) as 總人數 from 成績
再計算百分比:
select 課程,人數/總人數*100% as 百分比 from 各級別人數 group by 課程,類別
其他的統計也就雷同了。
⑽ sql查詢最高分和最低分
//查詢最高分
selectmax(score)fromstudent
//查詢最低分www.sz886.com
selectmin(score)fromstudent
//查詢最低分和最高分
selectmin(score)asmin_score,max(score)asmax_scorefromstudent