neo4j如何在路径的节点上使用count(distinct())
我搜索我的图的最长路径,我想计算这个最长路径的不同节点的数量 我想使用neo4j如何在路径的节点上使用count(distinct()),neo4j,cypher,Neo4j,Cypher,我搜索我的图的最长路径,我想计算这个最长路径的不同节点的数量 我想使用count(distinct()) 我试过两个问题 首先是 match p=(primero)-[:ResponseTo*]-(segundo) with max(length(p)) as lengthPath match p1=(primero)-[:ResponseTo*]-(segundo) where length(p1) = lengthPath return nodes(p1) 查询结果是一个带有路径节点的图
count(distinct())
我试过两个问题
首先是
match p=(primero)-[:ResponseTo*]-(segundo)
with max(length(p)) as lengthPath
match p1=(primero)-[:ResponseTo*]-(segundo)
where length(p1) = lengthPath
return nodes(p1)
查询结果是一个带有路径节点的图
但是如果我试着问
match p=(primero)-[:ResponseTo*]-(segundo)
with max(length(p)) as lengthPath
match p1=(primero)-[:ResponseTo*]-(segundo)
where length(p1) = lengthPath
return count(distinct(primero))
结果是
count(distinct(primero))
2
如何在节点primero上使用count(distinct())
节点PrimeRo有一个字段称为ID.< /P> < P>你应该至少绑定其中一个节点,添加一个方向,也考虑一个路径限制,否则这是一个非常昂贵的查询。
match p=(primero)-[:ResponseTo*..30]-(segundo)
with p order by length(p) desc limit 1
unwind nodes(p) as n
return distinct n;