Question

I'm trying to write a Cypher query that uses aggregation to pull back the most relevant paths. My desired path is described in the MATCH clause below

MATCH p=(a:TYP1)--(b:TYP2)--(c:TYP3)--(d:TYP4)
RETURN a, count(distinct d) as cntTYP4
ORDER BY cntTYP4 DESC

This produces a list of nodes of TYP1 sorted in descending order by the number of TYP4 nodes that they link to in the MATCH clause. What I would like to do is return all paths p where cntTYP4 > 5 (for example). My attempts to structure a query this far have been unsuccessful. Hopefully I'm missing something obvious!

Était-ce utile?

La solution

You can use WITH to do this. Something like:

MATCH p=(a:TYP1)--(b:TYP2)--(c:TYP3)--(d:TYP4)
WITH a, count(distinct d) as cntTYP4 
WHERE cntTYP4 > 5
RETURN a, cntTYP4
ORDER BY cntTYP4 DESC

HTH,

Andrés

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top