我有一个练习,我一直试图完成几个小时,但仍然没有运气。
问题:
列出所有借出书籍超过5本的客户的名称,地址e借书。
原理图如下图所示,到目前为止我已完成此查询,即缺少借出的图书数量
select
Name, Address
from
borrower
where
cardno in (select cardno
from book_loans
group by cardno
having count(cardno) in (select emprestimo.emprestimo
from
(select COUNT(cardno) as emprestimo
from book_loans
group by cardno
having COUNT(cardno) >= 5) emprestimo));
答案 0 :(得分:0)
既然你正在学习,我会给你伪代码。你知道有条款 - 它构成了寻找客户的基础。您通过加入借款人来应用该组ID(CardNo)。类似的东西:
select <columns>
from (query to find cardnos > 5 books>) as cards
inner join Borrower as brw on ...
order by ...;
并且好好学习下一课 - 如果没有order by子句,就不能保证结果集。