Show null counts with a condition of <= 2

时间:2015-04-29 00:35:00

标签: sql oracle count null left-join

Currently trying to find diagnosed diseases that have been diagnosed between 0-2 times. i am able to show how many times each disease has been diagnosed, including 0, but as soon as i try to view the ones that have a count of 0-2, my query doesn't work.

this gets me the counts (including 0):

select disease.name, count(diagnosed.diseaseid) as timesdiagnosed
from disease
left join diagnosed on disease.diseaseid = diagnosed.diseaseid
group by disease.name;

and this code doesn't work :

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;

My RDMBS is oracle.

1 个答案:

答案 0 :(得分:2)

true子句应该在test:start()之前和having之后:

order by