NEO4J - 递归查询聚合

时间:2015-12-04 18:32:24

标签: graph neo4j cypher

我有以下查询

MATCH (category:Category {id:'qwe'} )
MATCH (category)-[:CHILD_OF*0..50]->(subcats:Category)<-[:PHOTO_OF]-(photo:Photo)
return (subcats.name), count(photo)

此查询仅返回照片所属的确切类别的照片计数,我想要分类照片的聚合计数,包括子类别的照片,我想这曾经工作但在2.3.x更新后损坏。

1 个答案:

答案 0 :(得分:0)

尝试此查询:

MATCH (category:Category {id:'qwe'} )
MATCH (category)-[:CHILD_OF*0..50]->(subcats:Category)<-[:PHOTO_OF]-(photo:Photo)
WITH category.name AS cat, collect(subcats.name) AS subcats, count(photo) AS num
RETURN cat, subcats, num

这是你想要实现的行为吗?

我不确定您的查询在2.2.x和2.3之间可能发生了什么变化。您愿意分享您的数据,以便我们可以尝试重现吗?