sql練習題 答案

2023-02-04 10:30:04 字數 4668 閱讀 1202

access中sql專項訓練題(二)

(一)資料來源情況:以下各題操作表結構如下:

student(學生表)

cs(成績表):

course(課程表)

(二)針對學生課程資料庫查詢

(1) 查詢全體學生的學號與姓名。

select sno,sname from student

(2) 查詢全體學生的姓名、學號、所在系,並用別名顯示出結果。

select sname as '姓名',sno as '學號',dept as '所在地' from student

(3) 查詢全體學生的詳細記錄。

select * from student

(4) 查全體學生的姓名及其出生年份。

select sname,birth from student

(5) 查詢學校中有哪些系。

select distinct dept from student

(6) 查詢選修了課程的學生學號。

select sno from cs where cno is not null

(7) 查詢所有年齡在20歲以下的學生姓名及其年齡。

select sname,age from student where age < 20

(8) 查詢年齡在20~23歲(包括20歲和23歲)之間的學生的姓名、系別和年齡。

select sname,dept,age from student where age between 20 and 23

(9) 查詢年齡不在20~23歲之間的學生姓名、系別和年齡。

select sname,dept,age from student where age<20 or age>23

(10) 查詢資訊系、數學系和電腦科學系生的姓名和性別。

select sname,*** from student where dept='資訊系' or dept='數學系' or dept='電腦科學系'

(11) 查詢既不是資訊系、數學系,也不是電腦科學系的學生的姓名和性別。

select sname,*** from student where dept!='資訊系' and dept!='數學系' and dept!='電腦科學系'

(12) 查詢所有姓劉學生的姓名、學號和性別。

select sname,sno,*** from student where sname like('劉%')

(13) 查詢學號為2009011的學生的詳細情況。(具體的學號值根據表中資料確定)

select * from student where sno=5

(14) 查詢姓「歐陽」且全名為三個漢字的學生姓名

select sname from student where sname like('歐陽_')

(15) 查詢名字中第2個字為「晨」字的學生的姓名和學號

select sname,sno from student where sname like('_晨')

(16) 查詢所有不姓劉的學生姓名。

select sname,sno from student where sname not like('劉%')

(17) 查詢sql課程的課程號和學分。

select cno from course where cname='sql'

(18) 查詢以"db_"開頭,且倒數第3個字元為 i的課程的詳細情況。

select * from course where cname like('db[_]%i__')

(19) 查詢缺少成績的學生的學號和相應的課程號。

select sno,cno from cs where cj is null

(20) 查所有有成績的學生學號和課程號。

select sno,cno from cs where cj is not null

(21) 查詢計算機系年齡在20歲以下的學生姓名。

select sname from student where age < 20 and dept='電腦科學系'

(22) 查詢資訊系、數學系和電腦科學系學生的姓名和性別。(使用多個條件表示式)

select sname,*** from student where dept='資訊系' or dept='數學系' or dept='電腦科學系'

(23) 查詢年齡在20~23歲(包括20歲和23歲)之間的學生的姓名、系別和年齡。(使用多個條件表示式)

select sname,dept,age from student where age between 20 and 23

(24) 查詢選修了3號課程的學生的學號及其成績,查詢結果按分數降序排列。

select sno,cj from cs where cno=3 order by cj desc

(25) 查詢全體學生情況,查詢結果按所在系的系號公升序排列,同一系中的學生按年齡降序排列。

select * from student order by dept asc,age desc

(26) 查詢學生總人數。

select count(*) from student

(27) 查詢選修了課程的學生人數。

select count(sno) from cs where cno is not null

(28) 計算1號課程的學生平均成績。

select **g(cj) from cs where cno=1

(29) 查詢選修1號課程的學生最高分數。

select max(cj) from cs where cno=1

(30) 求各個課程號及相應的選課人數。

select from course left join cs on group by

(31) 查詢選修了3門以上課程的學生學號。

select sno, count(cno) from cs group by sno h**ing count(cno)>3

(32) 查詢有3門以上課程是90分以上的學生的學號及(90分以上的)課程數。

select sno, count(cno) as '課程數' from cs where cj>90

group by sno h**ing count(cno)>=3

(33) 查詢學生2006011選修課程的總學分。

select sum(course) from course,cs where and

(34) 查詢每個學生選修課程的總學分。

select sno,sum(cj)from cs,course

where

group by sno

union

select sno, 0 from student

where sno not in (select sno from cs)

(35) 查詢每個學生及其選修課程的情況。

select from cs,course where

(36) 查詢選修2號課程且成績在90分以上的所有學生的學號、姓名

select sno,sname from student where sno=(select sno from cs where cno=2 and cj>90)

(37) 查詢每個學生的學號、姓名、選修的課程名及成績。

select

from student,course,cs where and

(38) 查詢與「劉晨」在同乙個系學習的學生(分別用巢狀查詢和連線查詢)

----巢狀查詢

select * from student where dept in

(select dept from student where sname='劉晨')

----連線查詢

select stu1.* from student as stu1,student as stu2

where and '劉晨'

----exists查詢

select * from student s1 where exists(

select * from student s2 where and

'劉晨')

(39) 查詢選修了課程名為「資訊系統」的學生學號和姓名

select sno,sname from student where sno in

(select sno from cs where cno in(select cno from course where cname='資訊系統'))

(40) 查詢其他系中比資訊系任意乙個(其中某乙個)學生年齡小的學生姓名和年齡

select sname,age from student where age (select age from student where dept='資訊系')

(41) 查詢其他系中比資訊系所有學生年齡都小的學生姓名及年齡。分別用all謂詞和集函式

----用all

select sname,age from student where age (select age from student where dept='資訊系')

----聚合函式

select sname,age from student where age <

(select min(age) from student where dept='資訊系')

(42) 查詢所有選修了1號課程的學生姓名。(分別用巢狀查詢和連查詢)

練習題答案

第六章正態分佈與醫學參考值範圍 練習題一 最佳選擇題 1.標準正態分佈曲線中間95 的面積所對應的橫座標u的範圍是 a.b.c.d.e.2.f分布 t分布 分布和正態分佈各有幾個引數 a.1,1,1,1 b.2,2,2,2 c.2,1,1,2 d.1,2,2,1 e.2,1,1,1 3.乙個樣本是否...

練習題答案

濕地練習題答案 2014 12 12 1 5 adddb 6 10 dbbcd 11 1 三江平原,緯度高氣候寒冷,地勢低平 若爾蓋海拔高,氣候寒冷,地勢平坦。4分 2 三江平原,過渡開墾 若爾蓋濕地,過度放牧。4分 建議 建立自然保護區,發展旅遊業 發展特色農業 發展農產品加工業 退耕還濕地。6分...

材料概論練習題答案

填空題 1 機械設計常用屈服強度和抗拉強度兩種強度指標。2 設計剛度好的零件,應根據剛度指標來選擇材料。3 tk是材料從韌性狀態轉變為脆性狀態時的溫度。4 衝擊韌性的單位是 j cm2 延伸率的單位是 屈服強度的單位是 mpa或n mm2 5 屈強比是屈服強度與抗拉強度之比。6 材料主要的工藝效能有...