日期:2014-05-16  浏览次数:20486 次

not exists 使用

数据库题:有一学生表student(sid,sname)和一张图书借阅表books_loaned(sid,bname),请通过sql语句查找出从未借过一本书的学生的列表(请使用not?? exist关键字)

?


create table student
(
?sid int ,
?sname varchar(50)
)

create table books_loaned(
?sid int,
?bname varchar(50)
)

insert into student values(1,'ss')
insert into student values(2,'oo')
insert into student values(3,'dd')
insert into student values(4,'gg')
insert into student values(5,'qq')
insert into student values(6,'ee')
insert into student values(7,'aa')

insert into books_loaned values(1,'sddds')
insert into books_loaned values(6,'ee')
insert into books_loaned values(7,'aa')

?

select?? *?? from?? student?? a?? where?? not?? exists?? (select?? *?? from?? books_loaned b where?? a.sid=b.sid)

?