+3 votes
in Databases by (59.4k 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 (353k points)
selected by
Best answer

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;

Related questions

+1 vote
1 answer
asked Jun 26, 2023 in Databases by phpuser (59.4k points)
+3 votes
1 answer
+4 votes
1 answer