【问题标题】:How can I use group by function in neo4j?如何在 neo4j 中按功能使用分组?
【发布时间】:2017-10-17 02:30:02
【问题描述】:

我是 neo4j 的新手,我不知道如何在 cypher 中使用“分组依据”功能。

我有这样的事情:

match(c:SEASON)<-[t:during]-(a:PLAYER)-[r:won]->(b:AWARD)
return r.year as year, t.team as team

返回以下内容:

year    team

2011      OCK
2011      OCK
2011      LAS
2010      LAS
2010      SEA
2010      OCK

我想要这个:

year    team     frequencies

2011     OCK        2
2011     LAS        1
2010     LAS        1
2010     SEA        1
2010     OCK        1

我知道如何在 SQL 中做到这一点,但在 cypher 中却不知道。 我对同一年频率最高的团队感兴趣,在这种情况下是 2011 年的 OCK。

提前致谢

【问题讨论】:

    标签: neo4j group-by cypher


    【解决方案1】:

    Cypher 没有明确的分组依据,而是由范围内的非聚合列形成分组键。这是生成聚合列的Cypher aggregation functions

    这是一个使用示例,使用 COUNT() 作为聚合列,将年份和团队字段隐式设为分组键:

    match(c:SEASON)<-[t:during]-(a:PLAYER)-[r:won]->(b:AWARD)
    return r.year as year, t.team as team, count(t.team) as frequency
    

    【讨论】:

    • 感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 1970-01-01
    相关资源
    最近更新 更多