显示条件为 <= 2 的空计数
Show null counts with a condition of <= 2
目前正在尝试查找已确诊 0-2 次的疾病。
我能够显示每种疾病被诊断出多少次,包括 0 次,但是当我尝试查看计数为 0-2 的疾病时,我的查询就不起作用了。
这让我得到了计数(包括 0):
select disease.name, count(diagnosed.diseaseid) as timesdiagnosed
from disease
left join diagnosed on disease.diseaseid = diagnosed.diseaseid
group by disease.name;
此代码无效:
select disease.name, count(diagnosed.diseaseid) as timesdiagnosed
from disease
left join diagnosed on disease.diseaseid = diagnosed.diseaseid
group by disease.name
order by disease.name
having count(diagnosed.diseaseid) <= 2;
我的 RDMBS 是 oracle。
having
子句应位于 order by
之前和 group by
之后:
select disease.name, count(diagnosed.diseaseid) as timesdiagnosed
from disease
left join diagnosed on disease.diseaseid = diagnosed.diseaseid
group by disease.name
having count(diagnosed.diseaseid) <= 2
order by disease.name
目前正在尝试查找已确诊 0-2 次的疾病。 我能够显示每种疾病被诊断出多少次,包括 0 次,但是当我尝试查看计数为 0-2 的疾病时,我的查询就不起作用了。
这让我得到了计数(包括 0):
select disease.name, count(diagnosed.diseaseid) as timesdiagnosed
from disease
left join diagnosed on disease.diseaseid = diagnosed.diseaseid
group by disease.name;
此代码无效:
select disease.name, count(diagnosed.diseaseid) as timesdiagnosed
from disease
left join diagnosed on disease.diseaseid = diagnosed.diseaseid
group by disease.name
order by disease.name
having count(diagnosed.diseaseid) <= 2;
我的 RDMBS 是 oracle。
having
子句应位于 order by
之前和 group by
之后:
select disease.name, count(diagnosed.diseaseid) as timesdiagnosed
from disease
left join diagnosed on disease.diseaseid = diagnosed.diseaseid
group by disease.name
having count(diagnosed.diseaseid) <= 2
order by disease.name