【问题标题】:Modify query to show only patientid not null修改查询以仅显示患者 ID 不为空
【发布时间】:2020-09-10 23:33:15
【问题描述】:
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 不为空的数据。最好的方法是什么,用例?或者这甚至可能吗?

我想优化这个查询。

【问题讨论】:

    标签: sql sql-server case where-clause sql-null


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-13
      • 2011-10-21
      • 1970-01-01
      • 1970-01-01
      • 2021-01-30
      • 2019-01-02
      • 1970-01-01
      相关资源
      最近更新 更多