如果我有一个查询,例如:
select column1, (
select count(*) from table2
) as some_count
from table1
where column1 = 'foo'
我可以在 where 子句中使用 column1
,但是如果我尝试添加
and some_count > 0
然后我收到一个错误,提示 some_count
不存在。我如何在 where 子句中使用它?
最佳答案
使用HAVING
select column1, (
select count(*) from table2
) as some_count
from table1
HAVING some_count > 0
关于mysql - 在 MySQL where 子句中使用生成的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3463452/