I have a graph of people and items. The relationship is one to many (a:Person)-[:has]->(b:Item)
. For an input list of items, I am trying to get a list of people that have that item, ordered by who has the most items in the list.
In the above image I would expect an output like:
[{"Person 1", count: 3},{"Person 2", count: 2},{"Person 3", count: 1}]
I tried a few variations of:
match(a:Person) match(b:Item) where b.label in ["Item 1", "Item 2", "Item 3"] return a,count( (a)-[:has]->(b))
and
match(n:Item) return n, size((n)-->()) as count
where the counts are correct but when I try to narrow the Items to a list the count is wrong.
Perhaps something like:
MATCH (a:Person)-[:has]->(b:Item)
RETURN a, count(b) ORDER by count(b) DESC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.