Getting top n records for each group in neo4j

后端 未结 3 982
心在旅途
心在旅途 2021-02-15 03:15

I need to group the data from a neo4j database and then to filter out everything except the top n records of every group.

Example:

I have two node

3条回答
  •  不要未来只要你来
    2021-02-15 03:49

    Use LIMIT combined with ORDER BY to get the top N of anything. For example, the top 5 scores would be:

    MATCH (node:MyScoreNode) 
    RETURN node
    ORDER BY node.score DESC
    LIMIT 5;
    

    The ORDER BY part ensures the highest scores show up first. The LIMIT gives you only the first 5, which since they're sorted, are always the highest.

提交回复
热议问题