我目前得到的查询结果是:
我正在寻找可提供此结果的查询:
我使用了以下查询,但得到了不希望的结果:
MATCH q = (r:Representative {name: "Graaf"})-[job:FACILITATED]->(b)-[x: jaar_sinds_registratie_coördinator]->(a)
WHERE a.year < 13 AND NOT b:VuurpijlMatch
WITH DISTINCT count(labels(b)) AS countlabel1, labels(b) as labelname1
WITH DISTINCT labelname1, countlabel1
MATCH q = (r:Representative {name: "Graaf"})-[job:FACILITATED]->(b)-[x: jaar_sinds_registratie_coördinator]->(a)
WHERE a.year > 24 AND NOT b:VuurpijlMatch
WITH DISTINCT count(labels(b)) AS countlabel2, labels(b) as labelname2, countlabel1
RETURN DISTINCT labelname2, countlabel2, countlabel1
谁能给我一个答案/告诉我在这种情况下我忽略了什么?
谢谢你!
1条答案
按热度按时间yeotifhr1#
问题出在此汇总运算
WITH DISTINCT count(labels(b)) AS countlabel2, labels(b) as labelname2, countlabel1
。当您执行此运算时,countlabel2
会针对labelname2
和countlabel1
的每个不同组合进行计算。这就是为何会出现重复记录的原因。作为参考,您的countlabel2
会针对下列组合进行计算:这可以通过在
WITH
中提取labelname1来解决,这样聚合的组合就变成了:在这之后,我们可以简单地返回行,其中
labelname1
等于labelname2
。因此,您的查询现在变成这样: