第2章:DML和DQL——课后作业

#使用子查询获得当前没有被读者借阅的图书信息,要求:输出图书名称,图书编号,作者姓名,出版社和单价
SELECT`bid`,`bName`,`author`,`pubComp`,`price`FROM `book` WHERE `bid` NOT IN(SELECT `nif` FROM `borrow`);

#使用子查询获得今年的所有缴纳罚款的读者清单,要求输出的数据包括读者姓名。图书名称,罚款日期和缴纳罚金等
SELECT reader.rName ,book.bName,pDate ,amount FROM (penalty INNER JOIN reader ON penalty.rid = reader.rid) INNER JOIN book ON book.bid = penalty.bid  WHERE YEAR(pDate)=YEAR(NOW());

#使用子查询获得地址为空的所有读者尚未归还的图书清单,要求:安读者编号从高到低,借书日期由近致远的顺序输出读者编号,读者姓名,图书名称,借书日期和应归还日期
SELECT borrow.rid reader.rName ,book.bName ,lendDate ,willDate ,returnDate FROM (borrow INNER JOIN reader ON borrow.rid = reader.rid) INNER JOIN book ON book.bid = borrow.nif WHERE borrow.rid in(
SELECT reader.rid FROM reader WHERE rAddress IS NULL
)AND returnDate IS NULL ORDER BY borrow.rid DESC,lendDate ASC;        #查询

你可能感兴趣的:(java数据库,编程技术)