最完整的sql练习+答案上课讲义文档格式.docx

上传人:b****1 文档编号:13349980 上传时间:2022-10-10 格式:DOCX 页数:17 大小:241.55KB
下载 相关 举报
最完整的sql练习+答案上课讲义文档格式.docx_第1页
第1页 / 共17页
最完整的sql练习+答案上课讲义文档格式.docx_第2页
第2页 / 共17页
最完整的sql练习+答案上课讲义文档格式.docx_第3页
第3页 / 共17页
最完整的sql练习+答案上课讲义文档格式.docx_第4页
第4页 / 共17页
最完整的sql练习+答案上课讲义文档格式.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

最完整的sql练习+答案上课讲义文档格式.docx

《最完整的sql练习+答案上课讲义文档格式.docx》由会员分享,可在线阅读,更多相关《最完整的sql练习+答案上课讲义文档格式.docx(17页珍藏版)》请在冰豆网上搜索。

最完整的sql练习+答案上课讲义文档格式.docx

--所在班级

classvarchar(5)

createtableteacher

--教工编号

tnovarchar(3)notnullprimarykey,

--教工姓名

tnamevarchar(4)notnull,

--教工性别

tsexvarchar

(2)notnull,

--教工出生日期

tbirthdaydatetime,

--职称

profvarchar(6),

--所在部门

departvarchar(10)

createtablecourse

--课程号

cnovarchar(5)notnullprimarykey,

--课程名称

cnamevarchar(10)notnull,

tnovarchar(3)referencesteacher(tno)

createtablescore

snovarchar(3)notnullreferencesstudent(sno),

cnovarchar(5)notnullreferencescourse(cno),

--成绩

degreedecimal(4,1)

insertintostudent

values('

108'

'

曾华'

男'

1977-09-01'

95033'

105'

匡明'

1975-10-02'

95031'

107'

王丽'

女'

1976-01-23'

101'

李军'

1976-02-20'

109'

王芳'

1975-02-10'

103'

陆君'

1974-06-03'

insertintoteacher

804'

李诚'

1958-12-02'

副教授'

计算机系'

856'

张旭'

1969-03-12'

讲师'

电子工程系'

825'

王萍'

1972-05-05'

助教'

831'

刘冰'

1958-08-14'

insertintocourse

3-105'

计算机导论'

3-245'

操作系统'

6-166'

数字电路'

9-888'

高等数学'

insertintoscore

86'

75'

68'

92'

88'

76'

64'

91'

78'

85'

79'

81'

select*fromstudent

select*fromteacher

select*fromcourse

select*fromscore

--1、查询Student表中的所有记录的Sname、Ssex和Class列。

selectsname,ssex,classfromstudent

--2、查询教师所有的单位即不重复的Depart列。

selectdistinctdepartfromteacher

--3、查询Student表的所有记录。

--4、查询Score表中成绩在60到80之间的所有记录。

select*fromscorewheredegreebetween60and80

--5、查询Score表中成绩为85,86或88的记录。

select*fromscorewheredegree='

ordegree='

--6、查询Student表中“95031”班或性别为“女”的同学记录。

select*fromstudentwhereclass='

orssex='

--7、以Class降序查询Student表的所有记录。

select*fromstudentorderbyclassdesc

--8、以Cno升序、Degree降序查询Score表的所有记录。

select*fromscoreorderbycno,degreedesc

--9、查询“95031”班的学生人数。

selectcount(sno)fromstudentwhereclass='

--10、查询Score表中的最高分的学生学号和课程号。

selectsno,cno,degreefromscorewheredegreein(selectmax(degree)fromscore)

--11、查询‘3-105’号课程的平均分。

selectavg(degree)fromscorewherecno='

--12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。

selectavg(degree)fromscorewherecnolike'

3%'

andcnoin(selectcnofromscoregroupbycnohavingcount(cno)>

5)

--13、查询最低分大于70,最高分小于90的Sno列。

selectsnofromscorewheredegreebetween70and90

--14、查询所有学生的Sname、Cno和Degree列。

selectsname,cno,degreefromscore,studentwherestudent.sno=score.sno

--15、查询所有学生的Sno、Cname和Degree列。

selectcname,student.sno,degreefromscore,student,coursewherestudent.sno=score.snoando=o

--16、查询所有学生的Sname、Cname和Degree列

selectsname,cname,degreefromscore,student,coursewherestudent.sno=score.snoando=o

--17、查询“95033”班所选课程的平均分。

select平均分=avg(degree)fromcourse,student,scorewhereclass='

ando=oandstudent.sno=score.sno

--18、假设使用如下命令建立了一个grade表:

--createtablegrade(lowint,uppint,rankvarchar

(1))

--insertintogradevalues(90,100,'

A'

--insertintogradevalues(80,89,'

B'

--insertintogradevalues(70,79,'

C'

--insertintogradevalues(60,69,'

D'

--insertintogradevalues(0,59,'

E'

--现查询所有同学的Sno、Cno和rank列。

selectstudent.sno,cno,rankfromscore,student,gradewherestudent.sno=score.snoanddegreebetweenlowandupp

--19、查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。

//无关子查询

selectscore.sno,sname,ssex,sbirthday,class,o,cname,degreefromscore,student,coursewherestudent.sno=score.snoando=oando='

anddegree>

(selectdegreefromscorewheresno='

andcno='

--20、查询score中选学多门课程的同学中分数为非最高分成绩的记录。

selectsno,cno,degreefromscorewheredegreenotin(selectmax(degree)fromscoregroupbycno)orderbysno

--21、查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。

select*fromscorewheredegree>

(selectdegr

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > 公务员考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1