1.查询有过期未还图书的读者的书号、姓名、所在系
SELECT bor.BNO, bor.RNO, reader.RDE
FROM READER reader, BORROW bor
WHERE reader.RNO = bor.RNO
AND RDA > '2010-12-25'
--->'2010-12-25'为今天日期,不同SQL方言要做适当转换。
2.统计各个系读者的数量,显示系名和数量
SELECT RDE, COUNT(b.bno) AS 数量
FROM READER r LEFT JOIN BORROW b
ON r.RNO = b.RNO
GROUP BY b.RDE
3.查询借阅图书数量达到2本的读者信息
SELECT RNO, RN, RDE, RUP
FROM READER WHERE RNO IN (SELECT RNO FROM BORROW GROUP BY RNO HAVING COUNT(BNO) >=2)
4.查和“S0701026”读者借了相同图书的读者的图书证号和姓名
SELECT RNO, BNO
FROM BORROW
WHERE BNO IN (SELECT BNO FROM BORROW WHERE RNO = 'S0701026')
GROUP BY RNO
HAVING COUNT(BNO) = (SELECT COUNT(BNO) FROM BORROW WHERE RNO = 'S0701026')