資料庫 實驗二 資料庫的簡單查詢和連線查詢實驗

2021-10-10 22:57:11 字數 1559 閱讀 5026

– l)用transact-sql語句表示下列操作.在學生選課庫中實現其資料查詢操作.

– ①求數學系學生的學號和姓名。

select sno,sname from student where sdept=

'ma'

;

– ②求選修了課程的學生學號。

select

distinct sno from sc;

– ③求選修c1課程的學生學號和成績,並要求對查詢結果按成績降序排列,如果成績相同則按學號公升序排列。

select sno,grade from sc

where cno=

'c1'

order

by grade desc

,sno asc

;

– ④獲選修課程c1且成績在80~90分之間的學生學號和成績,並將成績乘以係數0.8輸出。

select sno,grade*

0.8from sc

where cno=

'c1'

and grade between

80and

90;

–⑤求數學系或計算機系姓張的學生的資訊。

select

*from student where sdept in

('ma'

,'cs'

)and sname like

'張%'

;

–(6)求缺少了成績的學生的學號和課程號。

select sno,cno from sc where grade is

null

;

–① 查詢每個學生的情況以及他(她)所選修的課程。

select s.

*,sc.

*,c.

*from student s,sc,course c

where s.sno=sc.sno and c.cno=sc.cno;

–② 學生的學號、姓名、選修的課程名及成績。

select s.sno,s.sname,c.cname,sc.grade from student s,sc,course c 

where s.sno=sc.sno and c.cno=sc.cno;

–③ 選修c1課程且成績為90分以上的學生學號、姓名及成績。

select s.sno,s.sname,sc.grade from student s,sc 

where s.sno=sc.sno and cno=

'c1'

and grade>

90;

–④ 查詢每一門課的間接先行課(即先行課的先行課)。

select c1.cno,c2.cpno from course c1,course c2 where c1.cpno=c2.cno;

資料庫 實驗二

1.簡單查詢 a 查詢 商號碼為s1的 商的名稱sname,所在城市city select sname,city from s where sno s1 b 查詢顏色為紅色的零件號碼 select pno from p where color 紅 c 查詢工程所在地為天津的工程名稱jname sel...

資料庫 簡單查詢

查詢單錶所有記錄,顯示所有字段值 select from 表名 查詢單錶所有記錄,顯示指定字段值 select 欄位1,欄位2,from 表名 條件查詢 select from 表名 where 條件1 or and 條件2.直接查詢 select 1 常量 select 1 2 計算器 呼叫函式 ...

資料庫簡單查詢

1 最簡單查詢 select from car 2 查詢制定列 select name oil,powers from car 3 對查出的列名修改名字 select name as 車名 oil as 油耗 powers as 動力 from car 4 按條件查詢 select name,oil...