修改查询以仅显示Patientid不为null

问题描述

SELECT patientname,patientID
 (CASE WHEN patientid is not null THEN 'yes'
             WHEN patientid is null then 'No'    
        END) as diagnosedornot

FROM database
where diagnosetime between '2020-09-03' and '2020-09-04'

有没有一种方法可以重写此查询以仅显示患者ID不为空,我的意思是显示仅显示患者ID不为空的数据。用例的最佳方法是什么?还是有可能?

我想优化此查询。

解决方法

使用where子句过滤非null patientid的行:

select patientname
from database
where 
    diagnosetime between '2020-09-03' and '2020-09-04' 
    and patientid is not null

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...