Neo4j Cypher:一个聚合函数在另一个之上

Neo4j Cypher:一个聚合函数在另一个之上,neo4j,cypher,aggregate,Neo4j,Cypher,Aggregate,我正在寻找一种在另一个聚合函数的结果之上执行一个聚合函数的方法。我特别想提出以下两个问题: MATCH (e :Event) - [:ATTENDED_BY] -> (a :Person) WITH e, collect(a) AS attendants WHERE ALL (a in attendants WHERE a.Company="XYZ") RETURN e.name AS name, count(*) as number_occurrences ORDER BY number

我正在寻找一种在另一个聚合函数的结果之上执行一个聚合函数的方法。我特别想提出以下两个问题:

MATCH (e :Event) - [:ATTENDED_BY] -> (a :Person)
WITH e, collect(a) AS attendants
WHERE ALL (a in attendants WHERE a.Company="XYZ")
RETURN e.name AS name, count(*) as number_occurrences
ORDER BY number_events DESC;

MATCH (e:Event) - [:ATTENDED_BY] -> (a :Person)
WITH e, collect(a) AS attendants
WHERE ALL (a in attendants WHERE a.Company="XYZ")
WITH e.name AS name, count(*) as number_occurrences
RETURN percentileDisc(number_occurrences,0.95) as percentile;

第一个查询提供了所有事件名称,其中只有来自单个公司(“XYZ”)的人员参加,以及这些事件的发生次数。第二个返回前5%最频繁事件的最小发生次数。我想得到的是这5%最频繁事件的名称和发生次数。有什么建议吗?

当然,我用WITH子句解决了这个查询,但关键是要正确理解它的用法。其思想是,只有最后一个with子句传递的变量才能进一步显示。这就是为什么在查询的第一部分中获得“percentile”变量后,我们需要在查询的第二部分中的所有后续WITH子句中继续传递它

MATCH (e :Event) - [:ATTENDED_BY] -> (a :Person)
WITH e, collect(a) AS attendants
WHERE ALL (a in attendants WHERE a.Company="XYZ")
WITH e.name AS name, count(*) as number_occurences
WITH percentileDisc(number_occurencies,0.95) as percentile
MATCH (e :Event) - [:ATTENDED_BY] -> (a :Person)
WITH percentile, e, collect(a) AS attendants
WHERE ALL (a in attendants WHERE a.Company="XYZ")
WITH percentile, e.name AS name, count(*) as number_occurences
WHERE number_occurences > percentile
RETURN name, number_occurences
ORDER BY number_occurences DESC