How do I achieve the equivalent of a SQL Having clause with Cypher

sql-having
knowledge-base

(Dana Canzano) #1

With a traditional SQL based database a HAVING clause will restrict aggregated values. For example

select zipcode, count(*) as population 
from Person 
group by zipcode
having population>100000;

will return all zipcodes which have more than 100k residents.
To achieve the same in Cypher use the following

match (n:Person) 
with n.zipcode as zip, count(*) as population 
where population>100000
return zip,population