sql - 重构 COALESCE 比较
问题描述
在OR
一个子句的部分,WHERE
我有这样的事情:
COALESCE(Table2.FireDate, Table1.HireDate,'06/06/2079') = ISNULL(Table3.DeathDate,'06/06/2079')
我想看看有没有办法避免COALESCE
通话并仍然达到相同的结果?如果可能的话,我希望获得一些性能。
解决方案
我不确定性能会更好。但是您可以根据需要摆脱合并:
declare @fireDate date = null -- '01/20/2017'
declare @hireDate date = '01/20/2017'
declare @deathDate date = '01/20/2017'
if (COALESCE(@fireDate, @hireDate, '06/06/2079') = ISNULL(@deathDate, '06/06/2079'))
begin
select '+'
end;
if(@fireDate is null and @hireDate is null and @deathDate is null)
or (@fireDate = @deathDate)
or (@fireDate is null and @hireDate = @deathDate) begin
select '+'
end;
推荐阅读
- python - 如何使 Google AI Platform 的 BASIC_GPU 规模层上的 GPU 对我的 tensorflow 程序可见?
- xcode - 在终端中使用 codesign 命令签名后,使用 Unity 构建的 macOS 应用程序在启动时挂起
- css - 如何强制 material-ui 生成!重要的 css 样式以防止 WordPress/Gutenberg css 样式冲突?
- java - BiometricPrompt.AuthenticationResult 中的 CryptoObject 始终为 null
- java - Keycloak 示例 - 方法 getValue() 未为 UserCredentialModel 类型定义
- c# - 带有 SpecFlow 挂钩的 NuGet 包
- swift - 如何在 Swift4 中不使用 inputIntensity 参数控制 CIFilter 的强度?
- python - 根据另一列中的值将列值从一列附加到另一列
- vim - 如何从 cnoremap 执行命令?
- java - 无法修复 AccessDeniedException