sql - 当列值为空时,不要在 where 条件中附加“and”子句
问题描述
我有一个查询,我不想在列值为空时在 where 条件中附加“and”子句,例如
select * from x where x.abc = 'ACTIVE' and x.start_date < sysdate and x.end_date > sysdate
因此,我希望 x.end_date 仅在其值不为 null 时才适用。没有任何存储过程,只是一个简单的查询。
我还想使用标准构建器和谓词将此查询转换为 spring-data jpa 规范。
解决方案
您可以使用or
:
select *
from x
where x.abc = 'ACTIVE' and
x.start_date < sysdate and
( x.end_date > sysdate or x.end_date is null );
推荐阅读
- javascript - 从 react-datetime 解析日期/时间值
- swift - 使用 RxTableView , mvvm 架构在 tableView 中显示空状态标签
- java - java.nio.file.NoSuchFileException - 从 GCS 下载文件
- javascript - 单击按钮时从 html 表中获取行
- c - 在 main 外部和 main 内部分配全局结构变量
- c++ - 为什么 c++ CUFFT 结果没有频率和幅度信息?
- android - GET_SIGNATURES 已弃用
- azure - aks 报告“吊舱不足”
- kubernetes - kubernetes (GKE) 上的 keycloak 部署:入口类 -- nginx VS gce
- vuejs2 - 跨浏览器平台测试