數(shù)據(jù)庫(kù)第二次試驗(yàn)_第1頁(yè)
數(shù)據(jù)庫(kù)第二次試驗(yàn)_第2頁(yè)
數(shù)據(jù)庫(kù)第二次試驗(yàn)_第3頁(yè)
數(shù)據(jù)庫(kù)第二次試驗(yàn)_第4頁(yè)
數(shù)據(jù)庫(kù)第二次試驗(yàn)_第5頁(yè)
已閱讀5頁(yè),還剩2頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、南昌航空大學(xué)實(shí)驗(yàn)報(bào)告2016 年 4 月 14日課程名稱:數(shù)據(jù)庫(kù)系統(tǒng)概論 實(shí)驗(yàn)名稱: SQL-select查詢操作 學(xué)號(hào): 14204129 姓名: 袁小峰 同組人: 指導(dǎo)教師評(píng)定: 簽名: 一、實(shí)驗(yàn)?zāi)康模罕砘蛞晥D數(shù)據(jù)的各種查詢(與統(tǒng)計(jì))SQL命令操作,具體分為:1、 了解查詢的概念和方法;2、 掌握SQL Sever集成管理器查詢子窗口中執(zhí)行SELECT操作方法;3、 掌握SELECT語(yǔ)句在單表查詢中的應(yīng)用;4、 掌握SELECT語(yǔ)句在多表查詢中的應(yīng)用;5、 掌握SELECT語(yǔ)句在復(fù)雜查詢中的使用方法;二、實(shí)驗(yàn)內(nèi)容與要求:請(qǐng)有選擇地實(shí)踐以下各題。(1)基于“教學(xué)管理”數(shù)據(jù)庫(kù)jxgl,試用SQ

2、L的查詢語(yǔ)句表達(dá)下列查詢: Jxgl數(shù)據(jù)庫(kù)的建立: 代碼:Create database jxglUSE jxglGOCreate Table Student(Sno CHAR(5) not null primary key(Sno), Sname varchar(20), Sage smallint check(Sage>=15 AND Sage<=45), Ssex char(2) default'男'check(Ssex='男' OR Ssex='女' ), Sdept char(2); Create Table Course

3、(Cno char(2)NOT NULL primary key(Cno), Cname VARCHAR(20), Cpno char(2), Ccredit SMALLINT); Create Table SC (Sno char(5) NOT NULL CONSTRAINT S_F FOREIGN KEY REFERENCES Student(Sno), Cno CHAR(2) NOT NULL, Grade smallint check (Grade IS NULL)OR(Grade between 0 and 100), Primary key(Sno,Cno), foreign ke

4、y(Cno) references Course(Cno); insert into Student values('98001','錢橫',18,'男','CS'); insert into Student values('98002','王林',19,'女','CS'); insert into Student values('98003','李民',20,'男','IS'); insert into

5、 Student values('98004','趙三',16,'女','MA'); insert into Course values('1','數(shù)據(jù)庫(kù)系統(tǒng)','5',4); insert into Course values('2','數(shù)學(xué)分析',null,2); insert into Course values('3','信息系統(tǒng)導(dǎo)論','1',3); insert into Course val

6、ues('4','操作系統(tǒng)_原理','6',3); insert into Course values('5','數(shù)據(jù)結(jié)構(gòu)','7',4); insert into Course values('6','數(shù)據(jù)處理基礎(chǔ)',null,4); insert into Course values('7','C語(yǔ)言','6',3); insert into SC values('98001','1'

7、,87); insert into SC values('98001','2',67); insert into SC values('98001','3',90); insert into SC values('98002','2',95); insert into SC values('98002','3',88);圖: Student表:Course表:SC表:1、 檢索年齡大于23歲的男學(xué)生的學(xué)號(hào)和姓名;代碼:select sno,sname 圖:from s

8、tudent where sage>23 and ssex='男'2、 檢索至少選修一門課程的學(xué)生的學(xué)號(hào)和姓名;代碼:select sname from studentwhere sno in圖: (select sno from sc )and ssex='女' 3、 檢索王同學(xué)不學(xué)的課程的課程號(hào);代碼:圖:select cno from courseexceptselect cnofrom sc where sno in (select sno from student where sname Like '王%' ); 4、 檢索至少選

9、修兩門課程的學(xué)生學(xué)號(hào);代碼:圖:select distinct s1.snofrom sc s1,sc s2where s1.sno=s2.sno and o!=o; 5、 檢索全部學(xué)生都選修的課程的課程號(hào)和課程名;代碼:select o,cnamefrom sc,coursewhere o=o 圖:group by o,cnamehaving count(*)= (select count(*) from Student ); 6、 檢索選修了所有3學(xué)分課程的學(xué)生學(xué)號(hào);代碼:圖:select sno from course,scwhere ccredit=3 and o=o; (2)基于“教

10、學(xué)管理”數(shù)據(jù)庫(kù)jxgl,試用SQL的查詢語(yǔ)句表達(dá)下列查詢:1、統(tǒng)計(jì)所有學(xué)生選修的課程門數(shù);代碼:select Student.sno,count(cno)from Student left outer join SC on (Student.sno = SC.sno)group by Student.Sno;圖: 2、求選修4號(hào)課程的學(xué)生的平均成績(jī);代碼:圖:select avg(sage) from studentwhere sno in (select sno from sc where cno='4' );3、求學(xué)分為3的每門課程的平均成績(jī);代碼:圖:select avg

11、(grade) from scwhere cno in (select cno from course where (ccredit=3);4、統(tǒng)計(jì)每門課程的學(xué)生選修人數(shù),超過(guò)3人的課程才統(tǒng)計(jì),要求輸出課程號(hào)和選修人數(shù),查詢結(jié)果按人數(shù)降序排列,若人數(shù)相同,按課程號(hào)升序排列;代碼:圖:select cno,count(sno) from scgroup by cnohaving count(*)>0order by count(*) desc,cno;5、 檢索學(xué)號(hào)比王林同學(xué)大,而年齡他小的學(xué)生姓名;代碼:圖:select sname from studentwhere sno >

12、(select sno from student where sname='王林' ) and sage < (select sage from student where sname='王林' ); 6、 檢索姓名以王字打頭的所有學(xué)生姓名和年齡;代碼:圖:select sname,sage from studentwhere sname like '王%'7、 在SC中檢索成績(jī)?yōu)榭罩档膶W(xué)生學(xué)號(hào)和課程號(hào);代碼:圖:select sno,cno from scwhere grade is null;8、 求年齡大于女同學(xué)平均年齡的男學(xué)生的姓名

13、和年齡;代碼:圖:select sname,sage from studentwhere ssex='男' and sage> (select avg(sage) from student where ssex='女' );9、 求年齡大于所有女同學(xué)年齡的男同學(xué)的姓名和年齡;代碼:圖:select sname,sage from studentwhere sage>all (select sage from student where ssex='女' );10、 檢索所有比“王林”年齡大的學(xué)生姓名、年齡和性別;代碼: 圖:selec

14、t sname,sage,ssex from studentwhere sage> (select sage from student where sname='王林' );11、 檢索選修2號(hào)課程的學(xué)生中成績(jī)最高的學(xué)生的學(xué)號(hào);代碼:圖:select sno from scwhere grade in (select max(grade) from sc where cno='2' ); 12、 檢索學(xué)生姓名及其所選修課程的課程號(hào)和成績(jī);代碼:圖:select sname,cno,grade from student,scwhere student.sno=sc.sno; 13、 檢索選修4門以上課程的學(xué)生總成績(jī)(不統(tǒng)計(jì)不及格的課程),并要求按總成績(jī)的

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論