【问题标题】:Anyway to add a constraint when using SQL count无论如何在使用 SQL 计数时添加约束
【发布时间】:2020-08-25 00:48:06
【问题描述】:
SELECT count(diabetesstatus is null) as atleast3, patientcountry
      
FROM database
where PJMEntryTime between '2020-08-24' and '2020-08-25'

and diabetesstatus is null and >= 3

group by patiencountry

我想使用 count 来包含患者没有糖尿病的标准,然后使用查询来

显示至少有 3 名未患糖尿病患者的国家/地区

我应该怎么做?使用 count 时如何包含约束?

是的,我认为这应该可行,基本上我的逻辑不是每个患者都是糖尿病患者。我想输入按国家/地区分组的查询,以便显示每个国家/地区至少有 3 名非糖尿病患者。

【问题讨论】:

    标签: sql count null


    【解决方案1】:

    我想你想要一个having 子句:

    SELECT patientcountry, count(*)
    FROM database
    WHERE PJMEntryTime between '2020-08-24' and '2020-08-25' AND
          diabetesstatus is null
    GROUP BY patiencountry
    HAVING COUNT(*) >= 3;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-22
      相关资源
      最近更新 更多