Cypher:一个聚合函数在另一个之上
Cypher: One aggregate function on top of the other
我正在寻找一种方法来在另一个聚合函数的结果之上执行一个聚合函数。特别是,我想加入以下两个查询:
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") 的人参加的所有活动名称,以及这些活动的发生次数。第二个 returns 前 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
我正在寻找一种方法来在另一个聚合函数的结果之上执行一个聚合函数。特别是,我想加入以下两个查询:
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") 的人参加的所有活动名称,以及这些活动的发生次数。第二个 returns 前 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