Mysql 未定义列的Where子句
我正在写一个查询,但遇到了一个问题Mysql 未定义列的Where子句,mysql,where-clause,Mysql,Where Clause,我正在写一个查询,但遇到了一个问题 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 countBL.card_no>1,因为它表示组函数的使用无效。但是我需要确保只显示大于1的卡号计数,否则我怎么
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 countBL.card_no>1,因为它表示组函数的使用无效。但是我需要确保只显示大于1的卡号计数,否则我怎么做?您必须将谓词放在HAVING子句中:
对于聚合函数,使用have代替where
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;
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;