sql - SQL server WHERE 子句中的排除
问题描述
我只想排除如果 ColumnA = 'SA' 排除 ColumnB 不像 '%Prev%' 和 ColumnB 不像 '%old%'。如果 columnA = 'BA' 我想保留它们。经验:
select columnA from Table where columnA ='SA' and ColumnB not like '%Prev%' and ColumnB not like '%old%'
解决方案
你想要or
:
select columnA
from Table
where (columnA = 'SA' and ColumnB not like '%Prev%' and ColumnB not like '%old%') or
columnA <> 'SA'
如果columnA
可以NULL
,逻辑也需要考虑到这一点。
推荐阅读
- registry - NSIS 注册表:写不写所有需要的值
- angular - 如何使我的 Angular 应用程序 500K 或更少?
- java - 如何将值粘贴到 Java JOptionPane showInputDialog 框中而不是键入
- postgresql - 没有自定义转换器的 jOOQ 查询表达式类型安全
- c# - 测试多边形的点是顺时针还是逆时针列出
- node.js - 使 Typescript 在 MacOS-catalina 上的 Visual Studio Code 中工作的问题
- xamarin.android - Xamarin 目标框架未更新
- java - 基于此代码Java的文件的每个句子中有多少个单词
- github - 在 GitHub 中搜索文本
- matlab - 如何在 Matlab 中“漂亮地打印”传递函数?