Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 未定义列的Where子句_Mysql_Where Clause - Fatal编程技术网

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;