apoc.agg.statistics函数
语法 |
|
||
描述 |
返回给定集合中 |
||
参数 |
名称 |
类型 |
描述 |
|
|
要聚合的值。 |
|
|
|
获取值所依据的百分位数。默认值为: |
|
返回 |
|
||
使用示例
本节中的示例基于以下示例图
CREATE (TopGun:Movie {title:"Top Gun", released:1986, tagline:'I feel the need, the need for speed.'})
CREATE (SleeplessInSeattle:Movie {title:'Sleepless in Seattle', released:1993, tagline:'What if someone you never met, someone you never saw, someone you never knew was the only someone for you?'})
CREATE (ThatThingYouDo:Movie {title:'That Thing You Do', released:1996, tagline:'In every life there comes a time when that thing you dream becomes that thing you do'})
CREATE (TheDevilsAdvocate:Movie {title:"The Devil's Advocate", released:1997, tagline:'Evil has its winning ways'})
CREATE (AsGoodAsItGets:Movie {title:'As Good as It Gets', released:1997, tagline:'A comedy from the heart that goes for the throat.'})
CREATE (YouveGotMail:Movie {title:"You've Got Mail", released:1998, tagline:'At odds in life... in love on-line.'})
CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
CREATE (SnowFallingonCedars:Movie {title:'Snow Falling on Cedars', released:1999, tagline:'First loves last. Forever.'})
CREATE (JerryMaguire:Movie {title:'Jerry Maguire', released:2000, tagline:'The rest of his life begins now.'});
CREATE (TheMatrixReloaded:Movie {title:'The Matrix Reloaded', released:2003, tagline:'Free your mind'})
我们可以通过运行以下查询,获取电影发行年份的不同统计指标
MATCH (movie:Movie)
RETURN apoc.agg.statistics(movie.released) AS stats;
| stats |
|---|
{total: 10, min: 1986, minNonZero: 1986.0, max: 2003, mean: 1996.8, |
我们可以通过对映射的 keys 使用 UNWIND 子句,将值映射展开为每行一个键
MATCH (movie:Movie)
WITH apoc.agg.statistics(movie.released) AS stats
UNWIND keys(stats) AS key
RETURN key, stats[key] AS value;
| 键 (key) | 值 |
|---|---|
"total" |
10 |
"min" |
1986 |
"minNonZero" |
1986.0 |
"max" |
2003 |
"mean" |
1996.8 |
"0.5" |
1997 |
"0.99" |
2003 |
"0.75" |
1999 |
"0.9" |
2000 |
"0.95" |
2003 |
"stdev" |
4.3772137256478585 |
默认情况下,该函数将返回 0.5、0.75、0.9、0.95 和 0.99 百分位数,但我们也可以传入自定义的百分位数(第二个参数)
MATCH (movie:Movie)
WITH apoc.agg.statistics(movie.released, [0.1, 0.25]) AS stats
UNWIND keys(stats) AS key
RETURN key, stats[key] AS value;
| 键 (key) | 值 |
|---|---|
"total" |
10 |
"min" |
1986 |
"minNonZero" |
1986.0 |
"0.1" |
1986 |
"max" |
2003 |
"mean" |
1996.8 |
"0.25" |
1996 |
"stdev" |
4.3772137256478585 |