Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-18-2020 02:44 PM
Hi everyone,
I am new to Neo4j and trying to find the count of all nodes grouped on label based on the following scenario where property of NodeE is not equal i.e. NodeE.prop <> NodeE.prop (E.g. end1 <> end2)
Expected count output Nodes badchild1 and subchild2 are ignored
NodeA -2
NodeB-2
NodeC-1
NodeD-1
NodeE-2
I would greatly appreciate any help.
Thanks
12-18-2020 06:57 PM
Hi neo4j.ardor,
My understanding of the problem is that in your result set you do not want to display nodes that have outgoing edges to same end nodes and those end nodes must have the label NodeE. So based on this understanding i propose the following solution:
QUERY
Match()-->(node2Delete:NodeE)<--()
With node2Delete as node2Delete
Match (startNode)-->(endNode)
Where endNode.name = node2Delete.name
With collect(distinct startNode.name) + collect(node2Delete.name) as nInclude
Match (allNodes)
Where not allNodes.name in nInclude
With Labels(allNodes) as labl
Return labl, count(labl)
DATABASE
Create (r1:NodeA{name:"root1"})-[:rel1]->(c1:NodeB{name:"child1"}),
(r2:NodeA{name:"root2"})-[:rel1]->(c2:NodeB{name:"child2"}),
(c1)-[:rel2]->(c2),
(c1)-[:rel3]->(sb1:NodeC{name:"subchild1"}),
(c1)-[:rel4]->(bch1:NodeD{name:"badchild1"}),
(c2)-[:rel3]->(sb2:NodeC{name:"subchild2"}),
(c2)-[:rel4]->(bch2:NodeD{name:"badchild2"}),
(sb1)-[:rel5]->(end1:NodeE{name:"end1"}),
(bch1)-[:rel5]->(end3:NodeE{name:"end3"}),
(sb2)-[:rel5]->(end3),
(bch2)-[:rel5]->(end2:NodeE{name:"end2"})
All the sessions of the conference are now available online