【文章內(nèi)容簡(jiǎn)介】
了 2門課的同學(xué)的信息 嵌套查詢: SFW 模塊中嵌套了SFW模塊 ? 查詢所有與“劉晨”同系的同學(xué)的信息 Select student.* select student.* From student from student Where sdept in where sdept=( (select sdept select sdept from student from student where sname=“劉晨” ) where sname=“劉晨” ) 還有什么方法完成這個(gè)查詢? 查詢選修了“信息系統(tǒng)”這門課的所有學(xué)生的姓名 Select sname select sname From student from student,SC, course Where sno in ( where ame=“信息系統(tǒng)” select sno and = from SC and = where o in ( select o from course where ame=“信息系統(tǒng)”)) 帶 all 或 any 的子查詢 ? 查詢其他系中年齡不比信息系中所有學(xué)生的年齡都大的學(xué)生的信息 Select * from student where sdept’IS’ and sage any (select sage from student where sdept=‘IS’) Select * from student Where sdept’IS’ and sage (select max(sage) from student where sdept=‘IS’) 那么,如何找出比信息系所有同學(xué)年齡都小的其他系的同學(xué)的信息? 帶 exist 的子查詢 ? 查詢所有選修了 1號(hào)課程的學(xué)生的姓名 Select sname from student where exists ( select * from SC where sno= and o=‘1’) sno sage 95001 95002 21 20 sdept IS CS sname Eva Mark student sno grade 95001 95001 95002 80 77 75 o 1 2 1 SC 帶 exist 的子查詢 ? 查詢所有沒(méi)有選修 1號(hào)課程的學(xué)生的姓名 Select sname from student where not exists ( select * from SC where sno= and o=‘1’) 查詢選修了所有課程的學(xué)生的姓名 Select * from student Where not exists ( select * from course where not exists (select * from SC where = and =)) Sno Sname Ssex Sage Sdept 202115121 202115122 202115123 202115125 李勇 劉晨 王敏 張立 男 女 女 男 20 19 18 19 CS CS MA IS Cno Cname Cpno Ccredit 1 2 3 4 5 6 7 數(shù)據(jù)庫(kù) 數(shù)學(xué) 信息系統(tǒng) 操作系統(tǒng) 數(shù)據(jù)結(jié)構(gòu) 數(shù)據(jù)處理 PASCAL語(yǔ)言 5 1 6 7 6 4 2 4 3 4 2 4 Sno Cno Grade 202115121 202115121 202115121 202115122 202115122 1 2 3 2 3 92 85 88 90 80 帶 exist 的子查詢 ? 查詢至少選修了學(xué)生 95002選修的所有課程的學(xué)生的學(xué)號(hào) Select sno from SC X Where not exists ( select * from SC Y where sno=‘95002’ and not exists ( select * from SC Z where = and = 查詢語(yǔ)句的完整格式 Select [all | distinct] 目標(biāo)列表達(dá)式 [別名 ][, 目標(biāo)列表達(dá)式 [別名 ]]… From 表名或視圖名 [別名 ][, 表名或視圖名 [別名 ]]… Where 條件表達(dá)式 Group by 列名 [having 條件表達(dá)式 ] Order by 列名 1 [ASC | Desc] [, 列名 1 [ASC | Desc]] 數(shù)據(jù)更新 ? 數(shù)據(jù)插入: insert ? 數(shù)據(jù)刪除 : delete ? 數(shù)據(jù)修改 : update 數(shù)據(jù)插入 ? 格式 1: Insert into 基本表名 [(列名表 )] value (元組值 ) ? 格式 2: Insert into 基本表名 [(列名表 )] value (元組值 ), (元組值 ), (元組值 ), … ? 格式 3: Insert into 基本表名 [(列名表 )] Select 查詢語(yǔ)句 數(shù)據(jù)插入舉例 ? 在 Student表中插入一條新的記錄(‘ 05007’,’張?jiān)啤?,‘女’ ,20,’CS’) Insert into student values(‘05007’,’張?jiān)啤?,‘女’ ,20,’CS’)。 ? 在 student表中插入一條新的記錄(‘ 05008’,’師焉然’) Insert into student(sno