我有点卡住查询数组的内容,这是图的基础
(:A)-[:Q]-(:B)-[:R]-(:C)
查询的初始部分匹配[:R]的其他数据属性我可以轻松完成并使用
返回匹配节点的总数(c)MATCH (a:A)-[:Q]-(b:B)-[r:R]-(c:C)
WHERE a.ID = currentID AND r.x = 1 AND r.y =3 AND r.z = 2<br/>
RETURN COUNT(c)
但是[:R]的属性是一个包含其他(:C)节点ID的数组,我想要的是返回(:C)发生的降序。
查询的示例结果将是
(:A)-[:Q]-(:B)-[1:R {ids: [2,3,4]} ]-(:C {ID = 1})
(:A)-[:Q]-(:B)-[:R {ids: [7,3,4]} ]-(:C {ID = 2})
(:A)-[:Q]-(:B)-[:R {ids: [1,4]} ]-(:C {ID = 3})
(:A)-[:Q]-(:B)-[:R {ids: [1]} ]-(:C {ID = 4})……
并返回此
(:C {ID = 4}) = 3
(:C {ID = 1}) = 2
(:C {ID = 3}) = 2
(:C {ID = 2}) = 1
(:C {ID = 7}) = 1
这是完全可能的,还是我可以获得ID和计数的列表,然后告诉应用程序使用ID检索数据?
4 = 3
1 = 2
3 = 2
2 = 1
7 = 1
如果无法做到这一点,我是否需要重新构建图表并在C之间添加额外的关系,
(:A)-[:Q]-(b:B)-[:R]-(c1:C)-[:R2 {property = b.ID}]-(c2:C)
如果是这样,我会将原始的MATCH查询扩展为类似
的内容MATCH (b:B)-[r:R1]-(c1:C)-[q:R2]-(c2:C)
WHERE r.x = 1 AND r.y =3 AND r.z = 2 and q.property = b.ID;
从这里开始如何按顺序列出c2?
答案 0 :(得分:0)
好的,发布后发现UNWIND不久,这是一个有效的解决方案
MATCH (b:B)-[r:R]->(c:C)
WHERE a.ID = currentID AND r.x = 1 AND r.y =3 AND r.z = 2
UNWIND r.ids AS ids
WITH ids ORDER BY ids
MATCH (d:C) WHERE d.ID = ids
RETURN DISTINCT(d), COUNT(d)
ORDER BY count(d) DESC