㈠ 按照人名查出學生的各科成績以及總成績並按總成績排名的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實現按總成績倒敘排列。
(1)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語句完成
use tempdb;
--創建成績表
create table 成績表
(
學科 varchar(20),
姓名 varchar(20),
成績 int
);
--插入數據
insert into 成績表
select '英語','甲',60 union
select '英語','乙',70 union
select '英語','丙',50 union
select '英語','丁',40 union
select '語文','甲',40 union
select '語文','乙',60 union
select '語文','丙',70 union
select '語文','丁',40 union
select '數學','甲',40 union
select '數學','乙',60 union
select '數學','丙',70 union
select '數學','丁',60;
--篩選出成績相同的信息
select a.學科,a.姓名,b.成績 from
成績表 a join 成績表 b
on a.學科=b.學科 and a.成績=b.成績 and a.姓名<>b.姓名
㈢ sql語句篩選及格成績
以下語句可實現只顯示同學的及格成績:
select 學號,語文=(case when 語文>=60 then 語文 else Null end),數學=(case when 數學>=60 then 數學 else Null end),英語=(case when 英語>=60 then 英語 else Null end) from 成績表 where 語文>=60 or 數學>=60 or 英語>=60
㈣ 大佬們 sql查詢 查詢學生學過語文並且學過數學的 怎麼查
select 學號 from 學生表 where (select 成績 from 成績表 join 課程表 on 成績表.課程號=課程表.課程號 where 成績表.學號=學生表.學號 and 課程名='語文')>(select 成績 from 成績表 join 課程表 on 成績表.課程號=課程表.課程號 where 成績表.學號=學生表.學號 and 課程名='數學')
㈤ 查詢每個學生的各科成績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 學生表.學號,學生表.姓名,
average(成績表.成績) as 平均成績,
max(成績表.成績) as 最高成績,
min(成績表.成績) as 最低成績
from 學生表 left join 成績表 on 學生表.學號=成績表.學號
order by 學生表.學號
成績表可換成語文、數學、英語等,查詢結果就是各個學生相應課程的平均成績、歷史最高成績、歷史最低成績.
㈦ 語文,數學和英語的成績怎麼用sql語句顯示出來
case when語句x0dx0aselect 語文 ,x0dx0a(case 語文x0dx0a when 語文>=80 then '優秀'x0dx0a when 語文>=60 and 語文<80 then '及格'x0dx0a when 語文<60 then '不及格'x0dx0aend) as 語文是否合格,x0dx0a數學,x0dx0a(case 數學x0dx0a when 數學>=80 then '優秀'x0dx0a when 數學>=60 and 語文<80 then '及格'x0dx0a when 數學<60 then '不及格'x0dx0aend) as 數學是否合格,x0dx0a英語,x0dx0a(case 英語x0dx0a when 英語>=80 then '優秀'x0dx0a when 英語>=60 and 英語<80 then '及格'x0dx0a when 英語<60 then '不及格'x0dx0aend) as 英語是否合格,x0dx0a from 成績表 where ......
㈧ 有個SQL查詢語句請教大家: 選出 「語文」和「數學」都選修並且語文成績比數學成績高的所有學生的姓名
select aa.sid,s.sname from
(select sc.sid,sc.cid,sc.score,c.cname
from sc inner join cource c on sc.cid = c.cid
where c.cname in('語文','數學')) aa
inner join student s on aa.sid = s.sid
group by aa.sid,s.sname
having count(aa.*) > 1 --此處選出同時選擇了「語文」和「數學」兩門課的學生
and sum(case aa.cname when '語文' then aa.score else 0 end) > sum(case aa.cname when '數學' then aa.score else 0 end) -- 次數選出「語文」成績大於「數學」成績的學生
㈨ 有個SQL查詢語句請教大家: 選出 「語文」和「數學」都選修並且語文成績比數學成績高的所有學生的姓名
student:s
course:c
teacher:t
sc:sc1,sc2
先分別選語文的和數學的選修學生和分數
1、create
view
yuwen
as
select
sid,score
from
sc1,c
where
c.cid=sc1.cid
and
c.cname=『語文'
2、create
view
shuxue
as
select
sid,score
from
sc2,c
where
c.cid=sc2.cid
and
c.cname=『數學'
然後選出以上數據中同時選了兩門課程且語文比數學成績高的學生
3、create
view
student_id
as
select
yuwen.sid
from
yuwen,shuxue
where
yuwen.score>shuxue.score
and
yuwen.sid=shuxue.sid
選出語文成績比數學成績高的學生的sid:最後的結果語句就有了:
4、select
s.sname
from
s,student_id
where
s.sid
=
student_id
也可以這樣寫:
1、create
view
yuwen
as
select
sname,sc1.sid,score
from
s,sc1,c
where
s.sid
=sc1.sid
and
c.cid=sc1.cid
and
c.cname=『語文'
2、create
view
shuxue
as
select
sname,
sc2.sid,score
from
sc2,c
where
c.cid=sc2.cid
and
c.cname=『數學'
3、select
sname
from
(select
yuwen.sname
from
yuwen,shuxue
where
yuwen.score>shuxue.score
and
yuwen.sid=shuxue.sid)
以上是一個詳細的分析過程。寫在一個句子里的話句子結構就有點復雜了。希望網友們補齊啊。