我正在撰写查询,但遇到了问题。
select name, address, count(BL.card_no)
from Book_Loans BL
inner join Borrower B on BL.card_no = B.card_no
where count(BL.card_no) > 1 group by name;
这不起作用,因为我不能使用“where count(BL.card_no)> 1”,因为它说“组功能的使用无效”。但我需要确保只显示大于1的卡号,我还能怎么做呢?
答案 0 :(得分:2)
您必须将谓词放在HAVING
子句中:
select name, address, count(BL.card_no)
from Book_Loans BL
inner join Borrower B on BL.card_no = B.card_no
group by name
having count(BL.card_no) > 1;
答案 1 :(得分:2)
用于聚合函数使用而不是在哪里
select name, address, count(BL.card_no)
from Book_Loans BL
inner join Borrower B on BL.card_no = B.card_no
group by name
having count(BL.card_no) > 1;