sql练习题+答案(2)

2019-09-02 14:56

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,sex 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 avg(cj) from cs where cno=1

(29) 查询选修1号课程的学生最高分数。

select max(cj) from cs where cno=1

(30) 求各个课程号及相应的选课人数。

select course.cno,count(cs.sno) from course

left join cs on course.cno=cs.cno group by course.cno

(31) 查询选修了3门以上课程的学生学号。

select sno, count(cno) from cs group by sno having count(cno)>3

(32) 查询有3门以上课程是90分以上的学生的学号及(90分以上的)课程数。

select sno, count(cno) as '课程数' from cs where cj>90 group by sno having count(cno)>=3

(33) 查询学生2006011选修课程的总学分。

select sum(course) from course,cs where course.cno=cs.sno and cs.sno=2006011

(34) 查询每个学生选修课程的总学分。

select sno,sum(cj)from cs,course where cs.cno=course.cno group by sno union

select sno, 0 from student where sno not in (select sno from cs)

(35) 查询每个学生及其选修课程的情况。

select cs.sno,course.* from cs,course where cs.cno=course.cno

(36) 查询选修2号课程且成绩在90分以上的所有学生的学号、姓名

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

(37) 查询每个学生的学号、姓名、选修的课程名及成绩。

select student.sno,sname,course.course,cs.cj from student,course,cs where student.sno=cs.sno and cs.cno=course.cno

(38) 查询与“刘晨”在同一个系学习的学生(分别用嵌套查询和连接查询)

----嵌套查询 select * from student where dept in (select dept from student where sname='刘晨

') ----连接查询 select stu1.* from student as stu1,student as stu2 where stu1.dept=stu2.dept and stu2.sname='刘晨' ----exists查询 select * from student s1 where exists( select * from student s2 where s1.dept=s2.dept and s2.sname='刘晨' )

(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

sql练习题+答案(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:北部新区H29地块项目可行性研究报告 - 图文

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: