0
votes

I am new to neo4j, I have the following situation

As shown in the figure above I have an Node Admin and nodes Folder1, Folder2,Folder3and other group of nodes like FileA,FileB,FileC,FileD.

  • The Admin node has an :access relationship with property qty for the Folder1,Folder2 and Folder3.

  • Each Folder nodes have :next relationship with respective File nodes as represented in the above figure.

Question :

How to write a Cypher query to return the distinct FileA , FileB ,FileC,FileD nodes from these folder nodes having maximum qty value?

I have tried,but I couldn't get it.

Please help, Thanks in advance

2

2 Answers

0
votes

What does high mean?

Try this:

MATCH (person:Person {name:"Admin"})-[r:access]->(folder)-[:next*]->(file)
WHERE r.qty > {high}
WITH file,r
ORDER r.qty DESC
RETURN distinct file

high is a parameter, e.g. {high:5}

0
votes

First, use http://console.neo4j.org/ for sharing test setups.

You want to use the MAX aggregator. The setup is a little weird because of how neo4j filtering works.

MATCH (n)-[r:access]->()
// Reduce all items to one row, and get max quantity
WITH COLLECT(r) as r,  MAX(r.qty) as maxvalue
// Unwind collected values, and cleanup variables with WITH
UNWIND r as r2 
WITH r2 as r, maxvalue
// Filter rows on max
WHERE r.qty=maxvalue
// Do stuff
return *

Or, if you have the luxery of APOC installed

MATCH (n)-[r:access]->()
// get max value
WITH r,  apoc.coll.max(COLLECT(r.qty)) as maxvalue
// Filter rows on max
WHERE r.qty=maxvalue
// Do stuff
return *