+3 votes
in Databases by (19.0k points)

In a drug database, some of the drugs have multiple ids. I want to select all drugs with more than 1 ids. Basically, I am trying to implement the GROUP BY and HAVING clause of SQL in Cypher. What is the equivalent for it?

My SQL query looks like this:

select name, count(id) as idcount

from drugs

group by name

having idcount>1;

1 Answer

+3 votes
by (51.1k points)

You can try the following Cypher query. You need to use the WITH clause to apply a filter to the aggregated results.

Here is the equivalent Cypher:

MATCH (d:drugs)
WITH d.name as drugLabel, COUNT(d.id) AS drugIdCount
WHERE drugIdCount>1
RETURN drugLabel, drugIdCount;
 


...