Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-17-2020 08:16 AM
Dear all,
I am looking for how to introduce constraints in EXIST clause.
If you consider relationship called REL with one property (share), I am looking for nodes such they have no parents via REL .
I woulk-d like something like
MATCH (n:NODE) WHERE NOT EXISTS( ()-[r:REL]->(n) WHERE r.share > 50.0) RETURN n
How can I rewrite this code to be runnable ?
Thnaks.
Alexandre
09-17-2020 08:34 AM
Hello @depire
OPTIONAL MATCH ()-[r:REL]->(n:NODE)
WHERE NOT EXISTS(()-[r]->(n))
OR r.share > 50.0
RETURN n
Regards,
Cobra
09-18-2020 01:20 AM
Unfortunately, this solution doesn't work, because the second clause must in the first clause.
To illustrate, I give the data.
CREATE (:LEU{LEID:"A"})
CREATE (:LEU{LEID:"B"})
CREATE (:LEU{LEID:"C"})
CREATE (:LEU{LEID:"D"})
CREATE (:LEU{LEID:"E"})
CREATE (:LEU{LEID:"F"})
CREATE (:LEU{LEID:"G"})
CREATE (:LEU{LEID:"H"})
MATCH (a:LEU{LEID:"A"})
MATCH (b:LEU{LEID:"B"})
CREATE (a)-[r:REL]->(b) SET r.share = 100.0, r.type=1
MATCH (b:LEU{LEID:"B"})
MATCH (a:LEU{LEID:"A"})
CREATE (b)-[r:REL]->(a) SET r.share = 10.0, r.type=1
MATCH (c:LEU{LEID:"C"})
MATCH (e:LEU{LEID:"E"})
CREATE (c)-[r:REL]->(e) SET r.share = 100.0, r.type=1
MATCH (d:LEU{LEID:"D"})
MATCH (e:LEU{LEID:"E"})
CREATE (d)-[r:REL]->(e) SET r.share = 100.0, r.type=2
MATCH (f:LEU{LEID:"F"})
MATCH (g:LEU{LEID:"G"})
CREATE (f)-[r:REL]->(g) SET r.share = 10.0, r.type=1
MATCH (g:LEU{LEID:"G"})
MATCH (h:LEU{LEID:"H"})
CREATE (g)-[r:REL]->(h) SET r.share = 100.0, r.type=1
After running wcc algorithm with r.share > 50.0, we have the following clusters:
0: A, B
1: C,D,E
2: G,H
3: F
My goal is to find the clusters with only one parent and returns the parent.
So I would like to retrieve something like:
Cluster Parent
0 A (because the relationship having B as parent is below 50.0)
2 G because F is not in the same cluster, because the share is below 50.0
3 F
Maybe it is more clear now.
Do you find the solution ?
All the sessions of the conference are now available online