假设我有一个这样的查询:
Select col1,
col2,
(select count(smthng) from table2) as 'records'
from table1
我想将它过滤为“记录”列不为空。
我不能做到这一点:
Select col1,
col2,
(select count(smthng) from table2) as 'records'
from table1
where records is not null
我想出的最好方法是将此结果集写入表值参数,并对该结果集进行单独查询。有任何想法吗?
最佳答案
只需将其移至派生查询即可。您不能在 WHERE 子句中使用在 SELECT 子句中定义的列。
Select col1, col2, records
from
(
Select col1,
col2,
(select ..... from table2) as records
from table1
) X
where records is not null;
关于sql - select中子查询语句的where子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13261071/