首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Not in to not exists

Not in to not exists
EN

Stack Overflow用户
提问于 2019-05-08 23:21:16
回答 1查看 39关注 0票数 0

我在select的where子句中有一个'not in‘,我试图将其转换为'not exists’

我尝试切换最小值,但没有填充任何内容(它确实执行了

代码语言:javascript
复制
where  [a] not in (
select 
    [a] 
from table
group by [a]
having count(*) > 1) -- Ignores Records with duplicate data
EN

回答 1

Stack Overflow用户

发布于 2019-05-08 23:23:01

您可以按如下方式执行此操作:

代码语言:javascript
复制
where not exists (select 1
                  from table t2
                  where ?.a = t2.a
                  group by t2.a
                  having count(*) > 1
                 )

不过,这通常是在查询的表中查找对相同值的另一个引用。如果是这样,请避免使用聚合:

代码语言:javascript
复制
where not exists (select 1
                  from table t2
                  where ?.a = t2.a and ?.id <> t2.id
                 )
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56044050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档