Graph
I've got a Neo4J database with broadly three types of graphs that look something like this:
A single cat, fed by two humans, who live in the same building
A single cat, who is being fed by multiple humans who all live in different buildings
Query
The data has lots of small graphs of this kind. I want to select the graphs where the Cat is fed by more humans than the humans have buildings. count(cat fed by human) > count(human lives in building)
for each graph.
To select cats with multiple humans I can run:
MATCH (cat:CAT)-[fed_by:FED_BY]-(:Human)
WITH cat, count(fed_by) as n_feeders
WHERE n_feeders > 1
MATCH g=(cat)-[:FED_BY]-(:Person)-[:LIVES_AT]-(:Building)
RETURN g
LIMIT 10
But how can I add the condition that the number of (:Cat)-[:FED_BY]-(:Human)
relationships must be greater than the number of (:Human)-[:LIVES_IN]-(:Building)
relationships?