sql – 对多个表使用NOT IN
发布时间:2021-03-30 18:20:54 所属栏目:MsSql 来源:互联网
导读:如何简化多个“不在”查询?使用多个子查询是否有效:不在(…)和不在(..)和不在(…) 我正在使用计数(抱歉忘记了) Select count (VisitorID) from Company where VisitorID not in (select VisitorID from UserLog where ActionID = 2 ) and VisitorID not in
如何简化多个“不在”查询?使用多个子查询是否有效:不在(…)和不在(..)和不在(…) 我正在使用计数(抱歉忘记了) Select count (VisitorID) from Company where VisitorID not in (select VisitorID from UserLog where ActionID = 2 ) and VisitorID not in (select VisitorID from Supplies where productID = 4) 解决方法Select count (VisitorID) from Company C where NOT EXISTS (select * from UserLog U where ActionID = 2 AND C.VisitorID = U.VisitorID) AND NOT EXISTS (select * from Supplies S where productID = 4 AND S.VisitorID = U.VisitorID) 为什么不存在? > NOT IN:UserLog或Supplies中的任何NULL VisitorID值表示不匹配 通常,NOT EXISTS是唯一正确的选项 (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- sql-server-2012 – 将维护计划复制到其他服务器
- Powershell Invoke-Sqlcmd的错误检测并不总是有效?
- sqlserver substring函数使用方法小结
- sql – 重写字段的外键
- sqlserver中根据字符分割字符串的最好的写法分享
- Sql Server 2005 默认端口修改方法
- winXP系统安装SQLServer2005开发版具体过程与注意问题
- sql-server – 无法在SQL Server 2012上运行的T-SQL CTE实现
- sql-server – Visual Studio和SQL Server – 正确的安装顺
- SQL Server:从VARCHAR(MAX)字段替换无效的XML字符