sql – select中子查询语句的Where子句
发布时间:2020-12-12 06:28:08 所属栏目:MsSql教程 来源:网络整理
导读:假设我有这样的查询: 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
假设我有这样的查询:
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 我想出的最好的方法是将此结果集写入Table Value参数,并对该结果集进行单独查询.有任何想法吗? 解决方法只需将其移动到派生查询即可.您不能使用WHERE子句中SELECT子句中定义的列.Select col1,records from ( Select col1,(select ..... from table2) as records from table1 ) X where records is not null; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |