接着教材数据库(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