加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 数据库 > MsSql > 正文

sql – select中子查询语句的Where子句

发布时间:2020-05-24 16:25:36 所属栏目:MsSql 来源:互联网
导读:假设我有这样的查询: Select col1, col2, (select count(smthng) from table2) as records from table1 我想过滤它为“记录”列不为空. 我不能做到这一点: Select col1, col2, (select

假设我有这样的查询:

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;

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读