我是靠谱客的博主 缓慢黑米,这篇文章主要介绍SQL数据库 【嵌套查询】,现在分享给大家,希望可以做个参考。

建立book数据库中完成下面查询:

(1)查找图书《C#程序设计案例教程》是由哪一家出版社出版的,查询

             出版社的名称。

复制代码
1
2
3
4
select 出版社名称 from 出版社表 where 出版社ID =(select 出版社 from 图书信息表 where 图书名称='C#程序设计案例教程')

(2)从“图书信息”数据表中查找价格最低并且出版日期最晚的图书信息。

复制代码
1
2
3
4
5
select * from 图书信息表 where 价格=(select MIN(价格)from 图书信息表) and 出版日期=(select MAX(出版日期)from 图书信息表 where 价格=(select MIN(价格)from 图书信息表))

(3)查询所有借阅了图书的借书证信息。

复制代码
1
2
3
select * from 借书证表 where 借书证编号 in (select 借书证编号 from 图书借阅表)

(4)查询由“高等教育出版社”出版已被借出的图书信息。

复制代码
1
2
3
4
5
6
select * from 图书信息表 where 出版社 =(select 出版社ID from 出版社表 where 出版社名称='高等教育出版社') and ISBN编号 in (select ISBN编号 from 藏书信息表 where 图书编号 in (select 图书编号 from 图书借阅表))

在gradem数据库中完成下面查询:

(1) 查询“李勇”同学所选课程的成绩。

复制代码
1
2
3
4
5
select degree from sc where sno =(select sno from student where sname='李勇')

(2) 查询比“信息系”所有学生年龄都要大的学生信息。

复制代码
1
2
3
4
5
select * from student where sbirthday <(select MIN (sbirthday) from student where sdept='信息系')

(3) 查询选修“数据库”课程且成绩在80~90分之间的学生学号及成绩。

复制代码
1
2
3
select sno 学号, B.degree 成绩 from course A, sc B where A.cno=B.cno and A.cname like '数据库'and degree between 80 and 90

(4) 查询没有选课的学生学号和姓名。

复制代码
1
2
3
4
select sno,sname from student where sno not in(select sno from sc)

(5) 查询选修“C04”课程的学生的平均年龄。

复制代码
1
2
3
select AVG (2022-year(sbirthday))平均年龄 from student,sc where student.sno=sc.sno and cno='C04'

(6) 查询有学生选的课程,显示课程编号,课程名称。

复制代码
1
2
3
4
select cno 课程号, cname 课程名 from course where cno in(select cno from sc)

(7) 查询与“李勇”同一个系的同学姓名。

复制代码
1
2
3
4
5
6
7
select sname from student where sdept=( select sdept from student where sname='李勇' ) and sname<>'李勇'

(8) 查询出生日期比“刘晨”同学大的学生学号,姓名,系别,插入到一张新表student2。

复制代码
1
2
3
4
5
6
7
select sno 学号,sname 学生姓名, sdept 系别 into student22 from student where (sbirthday>(select sbirthday from student where sname='刘晨'))

(9) 查询出生日期大于所有女同学出生日期的男同学的姓名及系别。

复制代码
1
2
3
4
5
6
select sname,sdept from student where (sbirthday <all( select sbirthday from student where ssex='女'))and ssex='男'

(11) 查询成绩高于或等于本人平均成绩的成绩。

复制代码
1
2
3
4
5
select degree from sc where degree>=(select AVG(degree) from sc where sc.cno=sc.cno)

最后

以上就是缓慢黑米最近收集整理的关于SQL数据库 【嵌套查询】的全部内容,更多相关SQL数据库内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(83)

评论列表共有 0 条评论

立即
投稿
返回
顶部