sql - SQL 查询 - 只显示非空行
问题描述
如果所有列(开始日期、开始日期 2、开始日期 3)都有空值,我不想检索所有行
+--------+------------+-------------+-------------+
| Id | Start Date | Start Date2 | Start Date3 |
+--------+------------+-------------+-------------+
| ABC123 | 10/15/2021 | null | null |
| ABC123 | null | null | null |
| ABC125 | 10/15/2021 | null | null |
| ABC126 | null | null | 10/15/2021 |
+--------+------------+-------------+-------------+
预期结果
+--------+------------+-------------+-------------+
| Id | Start Date | Start Date2 | Start Date3 |
+--------+------------+-------------+-------------+
| ABC123 | 10/15/2021 | null | null |
| ABC125 | 10/15/2021 | null | null |
| ABC126 | null | null | 10/15/2021 |
+--------+------------+-------------+-------------+
解决方案
您将使用一个where
子句并检查每一列:
select t.*
from t
where start_date is not null or start_date2 is not null or start_date3 is not null;
在一个表中包含三个名为“开始日期”的列似乎很尴尬。
推荐阅读
- woocommerce - 支持 HTTP API 运输计算所需的 Woocommerce 运输修改
- python - 时间戳字段在kibana中被解释为字符串而不是日期
- java - 如何将约束布局保存为全分辨率图像?
- android - 在片段导航组件之间传递数据的更好方法?
- flutter - 如何使用 sqflite Flutter 实现搜索委托
- docker - docker pull 不会从远程拉取最新的图像
- encryption - Jdk11 支持哪些 Cipher Suites 算法,哪一个最适合与 TLSv1.2 一起使用
- dart - Flutter/dart 中的 widget.something 实际调用了什么?
- amazon-web-services - 使用 SQS 模拟 SNS 中的消息持久性
- flutter - 应用程序在启动时因 firebase_admob 依赖项 0.8.0+4 而崩溃