neo4j 查询结果根据 return 节点和属性更改
neo4j query result changed base on return node and properties
我有一个包含 2 个不同 return 节点的查询。我的问题是为什么当我 return m2 节点时,结果会改变,而当从 return 语句中删除 m2 节点时,结果也会改变。结果 dcount 通过删除或添加 m2 进行更改。我的问题是为什么?!!
在 return 语句中使用 m2 的第一个查询:
MATCH (a1:Example)<-[r1:REL_EXAMPLE]-(a2:Example),
(a1)-[:REL_2_EXAMPLE]->(m1:Mexample),
(a2)-[:REL_2_EXAMPLE]->(m2:Mexample)
WHERE a1.key = 123456
AND a2.key <> a1.key
AND (r1.delta < 300 AND r1.delta > 20)
AND ((a1.love <> 0 OR a2.love <> 0) OR (abs(a1.love - a2.love) < 0.1))
WITH a1,a2,m1,m2,r1, CASE
WHEN exists((m1)<-[:REL_2_EXAMPLE]-(a2)) OR exists((m2)<-[:REL_2_EXAMPLE]-(a1)) THEN 0.20
ELSE 1
END AS factor
RETURN count(r1) * factor as dcount,a2.title as anode, a2.key as id, m2.full_name ORDER BY dcount DESC LIMIT 30;
第二个查询没有 m2:
MATCH (a1:Example)<-[r1:REL_EXAMPLE]-(a2:Example),
(a1)-[:REL_2_EXAMPLE]->(m1:Mexample),
(a2)-[:REL_2_EXAMPLE]->(m2:Mexample)
WHERE a1.key = 123456
AND a2.key <> a1.key
AND (r1.delta < 300 AND r1.delta > 20)
AND ((a1.love <> 0 OR a2.love <> 0) OR (abs(a1.love - a2.love) < 0.1))
WITH a1,a2,m1,m2,r1, CASE
WHEN exists((m1)<-[:REL_2_EXAMPLE]-(a2)) OR exists((m2)<-[:REL_2_EXAMPLE]-(a1)) THEN 0.20
ELSE 1
END AS factor
RETURN count(r1) * factor as dcount,a2.title as anode, a2.key as id ORDER BY dcount DESC LIMIT 30;
发生这种情况是因为您正在 return 语句中执行聚合操作。在 return 语句中使用 m2
的第一个查询中。
RETURN count(r1) * factor as dcount,a2.title as anode, a2.key as id, m2.full_name ORDER BY dcount DESC LIMIT 30;
dcount
是针对 a2.title
、a2.key
和 m2.full_name
.
的每个不同组合计算的
在第二个查询中,使用 return 语句
RETURN count(r1) * factor as dcount,a2.title as anode, a2.key as id ORDER BY dcount DESC LIMIT 30;
计算dcount
,对于a2.title
和a2.key
的每个不同组合,由于每个查询的聚合条件不同,因此结果不同。
我有一个包含 2 个不同 return 节点的查询。我的问题是为什么当我 return m2 节点时,结果会改变,而当从 return 语句中删除 m2 节点时,结果也会改变。结果 dcount 通过删除或添加 m2 进行更改。我的问题是为什么?!!
在 return 语句中使用 m2 的第一个查询:
MATCH (a1:Example)<-[r1:REL_EXAMPLE]-(a2:Example),
(a1)-[:REL_2_EXAMPLE]->(m1:Mexample),
(a2)-[:REL_2_EXAMPLE]->(m2:Mexample)
WHERE a1.key = 123456
AND a2.key <> a1.key
AND (r1.delta < 300 AND r1.delta > 20)
AND ((a1.love <> 0 OR a2.love <> 0) OR (abs(a1.love - a2.love) < 0.1))
WITH a1,a2,m1,m2,r1, CASE
WHEN exists((m1)<-[:REL_2_EXAMPLE]-(a2)) OR exists((m2)<-[:REL_2_EXAMPLE]-(a1)) THEN 0.20
ELSE 1
END AS factor
RETURN count(r1) * factor as dcount,a2.title as anode, a2.key as id, m2.full_name ORDER BY dcount DESC LIMIT 30;
第二个查询没有 m2:
MATCH (a1:Example)<-[r1:REL_EXAMPLE]-(a2:Example),
(a1)-[:REL_2_EXAMPLE]->(m1:Mexample),
(a2)-[:REL_2_EXAMPLE]->(m2:Mexample)
WHERE a1.key = 123456
AND a2.key <> a1.key
AND (r1.delta < 300 AND r1.delta > 20)
AND ((a1.love <> 0 OR a2.love <> 0) OR (abs(a1.love - a2.love) < 0.1))
WITH a1,a2,m1,m2,r1, CASE
WHEN exists((m1)<-[:REL_2_EXAMPLE]-(a2)) OR exists((m2)<-[:REL_2_EXAMPLE]-(a1)) THEN 0.20
ELSE 1
END AS factor
RETURN count(r1) * factor as dcount,a2.title as anode, a2.key as id ORDER BY dcount DESC LIMIT 30;
发生这种情况是因为您正在 return 语句中执行聚合操作。在 return 语句中使用 m2
的第一个查询中。
RETURN count(r1) * factor as dcount,a2.title as anode, a2.key as id, m2.full_name ORDER BY dcount DESC LIMIT 30;
dcount
是针对 a2.title
、a2.key
和 m2.full_name
.
在第二个查询中,使用 return 语句
RETURN count(r1) * factor as dcount,a2.title as anode, a2.key as id ORDER BY dcount DESC LIMIT 30;
计算dcount
,对于a2.title
和a2.key
的每个不同组合,由于每个查询的聚合条件不同,因此结果不同。