【SQL Server】教材数据库(3)

接着教材数据库(1)的内容,完成下列查询。

1 查询订购高等教育出版社教材的学生姓名

2 查询比所有高等教育出版社的图书都贵的图书信息

3 列出每位学生姓名、订购教材书名、价格。

1、嵌套查询:use jiaocai

select student.name from student,orders,book,publish

where publish.name = '高等教育出版社'

and student.id = orders.s_id

and orders.b_id = book.id

and book.c_id = publish.id

连接查询:select student.name

from student,orders,book,publish

where publish.name = '高等教育出版社'

and student.id = orders.s_id

and orders.b_id = book.id

and book.c_id = publish.id

语句无错误,不过在添加数据时我们没有添加名为高等教育出版社的信息,我们可以使用图形化的方法手动修改

再次执行语句可以得到第一问的结果

2、select * from book

where price > all(

select price from book

where id in(

select id from book

where c_id in(

select id from publish

where name = '高等教育出版社'

)

)

)

3、select name,title,price

from student

left join orders on student.id=orders.s_id

left join book on book.id=orders.b_id

相关推荐
RestCloud19 小时前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud19 小时前
为什么说零代码 ETL 是未来趋势?
数据库·api
ClouGence21 小时前
CloudCanal + Paimon + SelectDB 从 0 到 1 构建实时湖仓
数据库
DemonAvenger1 天前
NoSQL与MySQL混合架构设计:从入门到实战的最佳实践
数据库·mysql·性能优化
AAA修煤气灶刘哥2 天前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql
RestCloud2 天前
揭秘 CDC 技术:让数据库同步快人一步
数据库·api
得物技术2 天前
MySQL单表为何别超2000万行?揭秘B+树与16KB页的生死博弈|得物技术
数据库·后端·mysql
可涵不会debug2 天前
【IoTDB】时序数据库选型指南:工业大数据场景下的技术突围
数据库·时序数据库
ByteBlossom2 天前
MySQL 面试场景题之如何处理 BLOB 和CLOB 数据类型?
数据库·mysql·面试
麦兜*2 天前
MongoDB Atlas 云数据库实战:从零搭建全球多节点集群
java·数据库·spring boot·mongodb·spring·spring cloud