select b.*
from Books b,Record r
where b.bookid=r.bookid and datepart(mm,borrowbook)=7 and bookwriter='谭浩强'
我把7月被人借过的书查出来了..
但没有被借过的书应该怎么写去了,高手指点一下...
这样试试.
select *
from Books
where bookwriter='谭浩强' and
bookid not in (
select bookid
from Record inner join Books
on Record.bookid=Books.bookid
where datepart(mm,borrowbook)=7 and Books.bookwriter='谭浩强'
)
--使用NOT EXISTS,查询出在借阅记录Record中没有记录的就行了。select b.* from Books bwhere not exists(select 1 from Record rwhere r.bookid=b.bookid)