表
BOOK_COPIES (Book_ISBN [pk,fk], Branch_ID [pk,fk], Num_Copies)
BOOK_LOANS (Book_ISBN [pk,fk], Branch_ID [pk,fk],Card_Num [pk,fk], Date_Out,Date_Due)
BORROWER (Card_Num [pk], Name, Address, Phone)
问题
列出已签出最多图书的借款人的卡号和姓名。
解决方案:
select br.cardnum,br.name from borrower br, bookloans bl
where br.card_num=bl.card_num
group by br.cardnum,br.name
having count(bl.book_isbn)>=all(
select count(*) from bookloans bl
group by bl.card_num
);
请你帮我完成查询。
答案 0 :(得分:0)
好像你在考虑你的家庭作业:
select BOOK_LOANS.Card_Num, Name, COUNT(Book_ISBN) AS BorrowedCount
from BOOK_LOANS
left join BORROWER on
group by BOOK_LOANS.Card_Num
order by BorrowedCout desc
limit 1
不需要嵌套查询。