配色: 字号:
数据库系统概论论文
2022-10-17 | 阅:  转:  |  分享 
  
1.查询课程名有%字符的课程名和课程学分

selectcname,ccredit

fromdbo.c

wherecnamelike''%\%%''escape''\'';

2.查询没有成绩的学生学号

selectsno

fromdbo.sc

wheregradeisnull;

3.查询CS年龄小于25岁的学生姓名

selectsname

fromdbo.s

wheresdept=''cs''andsage<25;

4.查询选修课程的学生人数

selectcount(distinctsno)

fromdbo.sc;

5.s1学生平均分

selectavg(grade)

fromdbo.sc

wherecno=''s1'';

6.各学院女学生的人数

selectsdept,count(sno)

fromdbo.s

wheressex=''女''

groupbysdept;

7.查询没有分配系的学生学号和姓名,学号降序排列

selectsno,sname

fromdbo.s

wheresdeptisnull

orderbysnodesc;

8.查询每个系女生人数,超过2人的输出系名和女生人数

selectsdept,count(sno)

fromdbo.s

wheressex=''女''

groupbysdept

havingcount(sno)>2;

9.显示所有学生信息,如果该生参加过考试,显示其考试成绩

selectdbo.s.sno,sname,ssex,sage,sdept,grade

fromdbo.s

leftjoinscon(dbo.s.sno=dbo.sc.sno);

10.查询学分比maths少的课程号和课程名、学分

selects1.cno,s1.cname,s1.ccredit

fromdbo.cs1,dbo.cs2

wheres1.ccredit
11.CS系没有选修c3号课程的学生学号

selectsno

fromdbo.s

wheresdept=''cs''andnotexists

(select

fromdbo.sc

wheresno=dbo.s.snoandcno=''c3'');

12.被全部学生都选修的课程号、课程名

selectcno,cname

fromdbo.c

wherenotexists

(select

fromdbo.s

wherenotexists

(select

fromdbo.sc

wheresno=dbo.s.snoandcno=dbo.c.cno));

13.第一步:把maths不及格的成绩全部置空

updatedbo.sc

setgrade=null

wheregrade<60andcnoin

(selectcno

fromdbo.c

wherecname=''maths'');

第二步:查询选修maths课程的信息

select

fromdbo.c

wherecname=''maths'';

14、第一步:把全体女学生的学号、姓名、选课课号、课程名、成绩做成视图S_SC,

Createviews_sc

As

Selectdbo.s.sno,sname,dbo.c.cno,cname,grade

Fromdbo.s,dbo.sc,dbo.c

Wheredbo.s.sno=dbo.sc.snoanddbo.sc.cno=dbo.c.cnoandssex=''女'';

第二步:查询该视图所有信息

Selectfroms_sc





















献花(0)
+1
(本文系知识资料圈原创)