資料庫實驗報告
實驗三實驗題目:sql 基本表查詢
指導老師:***
實驗型別:驗證
實驗室:軟體實驗室二
專業班級:電腦科學與技術(網路工程方向)***班
姓名2023年 10月20 日
一、實驗題目
二、實驗目的和要求
熟練掌握查詢語句的一般格式,熟練掌握連線、巢狀和集合查詢的使用。
三、實驗內容
1. 查詢student表中的所有資訊、部分資訊。
注意:*的作用
2.查詢student表中計算機系學生的全部資訊、查詢student表中計算機系年齡在20歲以上的學生名單。
3.查詢選修了2號課程的學生名單。
注:分別用連線查詢、巢狀查詢實現,並比較
4.求每個學生的平均成績和每一門課的平均成績。
注:集函式的使用、列別名的使用
5.查詢沒有選修2號課程的學生姓名。
注:用相關子查詢和不相關子查詢兩種方法實現
6.查詢選修了全部課程的學生姓名。
注:全稱量詞的實現5.實驗中存在的問題
四、 實驗步驟
1. 開啟sql server management studio,選擇windows認證,建立stu資料庫,再建立student表,course表和sc表,如圖所示,並輸入資訊
2.右擊,新建查詢
1) 查詢student表中的所有資訊
select * from student
查詢student中計科系學生的姓名
select sname from student where sdept='計科系'
2) 查詢student表中計算機系學生的全部資訊
select * from student where sdept='計科系'
查詢student表中計科系年齡在20歲以上的學生名單
select sname,sage from student where sage>=20 and sdept='計科系'
3)查詢選修了003號課程的學生名單。(注:分別用連線查詢、巢狀查詢實現並比較)
巢狀查詢的查詢效率比連線查詢的效率更高。
select sname from student,sc where and cno='003'
select sname from student where sno in(select sno from sc where cno='003
4) 求每個學生的平均成績和每一門課的平均成績
select sname 姓名,**g(grade) 平均成績 from student,sc where group by sname
select cname 課程名,**g(grade) 平均成績 from course,sc where group by cname
5)查詢沒有選修006號課程的學生姓名。(注:用相關子查詢和不相關子查詢兩種方法實現)
select sname from student where sno not in(select sno from sc where cno= '006')
select sname from student x where sno not in (select sno from sc y where and cno='006')
6)查詢選修了全部課程的學生姓名。(注:全稱量詞的實現5.實驗中存在的問題)
select sname from student where not exists
(select * from course where not exists
(select * from sc where sno= and cno=
四、 實驗總結
通過這次實驗,我掌握了sql基本表的查詢功能,在實驗的過程中,對sql查詢語言有了更好的認識。熟練掌握了查詢語句的一般格式,而且掌握了連線、巢狀和集合查詢的使用。對以後的學習有了很大的幫助。
實驗三資料庫SQL基本表查詢
資料庫原理及應用實驗報告 實驗報告 實驗型別 綜合設計實驗室 軟體實驗室一 sql基本表查詢 1 實驗專案的目的和任務 熟練掌握查詢語句的一般格式,熟練掌握連線 巢狀和集合查詢的使用。2.程式 部分 select from student where s in select s from sc wh...
SQL模糊查詢
在進行資料庫查詢時,有完整查詢和模糊查詢之分。一般模糊查詢語句如下 select欄位from表where某欄位like條件 其中關於條件,sql提供了四種匹配模式 1,表示任意0個或多個字元。可匹配任意型別和長度的字元,有些情況下若是中文,請使用兩個百分號 比如select from user wh...
資料庫sql高階查詢教務 答案
設教學資料庫education有三個關係 學生關係s sno,sname,age,sdept 學習關係sc sno,cno,grade 課程關係c cno,cname,cdept,tname 查詢問題 1 查所有年齡在20歲以下的學生姓名及年齡。2 查考試成績有不及格的學生的學號 3 查所年齡在20...