sql - 为什么在 WHERE 子句中忽略 OR?
问题描述
我有以下握手表:
CREATE TABLE [dbo].[Handshake](
[Report Year] [varchar](100) NULL,
[Status] [varchar](100) NULL,
[Update Time] [datetime] NULL,
[Process Time] [datetime] NULL,
[Rejects?] [varchar](10) NULL
) ON [PRIMARY]
GO
如果我运行此查询,
SELECT TOP (1) *
FROM [dbo].[Handshake]
WHERE [Status] <> 'Loading' OR [Status] <> 'Processing' OR [Status] <> 'Processed' OR [Status] <> 'Process Failed'
ORDER BY [Update Time] DESC
我希望 WHERE 子句中指示的任何内容都不会被退回,但它是!例如,Processed
记录不应该被退回!!
这就是我得到的:
样本数据
Report Year Status Update Time Process Time Rejects?
2020 8+4 Processed 2020-10-09 16:58:05.610 2020-10-09 17:20:05.000 NULL
2020 8+4 Processed 2020-10-09 16:22:06.343 2020-10-09 16:53:26.000 NULL
2020 5+7 Processed 2020-09-29 18:09:00.000 2020-10-09 16:04:04.000 TRUE
2020 6+6 Failed 2020-09-29 17:21:00.000 NULL NULL
2020 5+7 Processed 2020-09-29 15:54:00.000 2020-10-09 16:04:04.000 NULL
解决方案
你似乎想要AND
,而不是OR
:
WHERE [Status] <> 'Loading'
AND [Status] <> 'Processing'
AND [Status] <> 'Processed'
AND [Status] <> 'Process Failed'
您也可以用以下方式表达这一点not in
:
WHERE [Status] NOT IN ('Loading', 'Processing', 'Processed', 'Process Failed')
推荐阅读
- r - 在 lapply 中跳过错误“选择了未定义的列”
- c# - 数字密码输入,从 0 到 9 只取 1 个值
- excel - Excel 等待用户操作时如何单击 Enter?
- c# - 如何正确使用高级自适应卡?
- datepicker - 我们如何在 Ionic 中设置最大日期
- spring-boot - 我应该明确验证 Keycloak 令牌还是由 Keycloak 适配器完成?
- python - 在 kaggle 控制台中看不到完整的错误日志
- linux - 如何在 yocto build 中将 libgif 添加为包
- spring-boot - 在docker容器内的外部tomcat上运行spring boot时出错
- python - python中两个不同数据帧之间的数值差异