问题描述
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