假设我有这样的查询:
Select col1,col2,(select count(smthng) from table2) as 'records' from table1
我想过滤它为“记录”列不为空.
我不能做到这一点:
Select col1,(select count(smthng) from table2) as 'records' from table1 where records is not null
解决方法
只需将其移动到派生查询即可.您不能使用WHERE子句中SELECT子句中定义的列.
Select col1,records from ( Select col1,(select ..... from table2) as records from table1 ) X where records is not null;