How to group and count relationships in cypher neo4j

How can I quickly count the number of “messages” made by one person and group them one by one in a cypher request?

Basically, I have message label nodes and the users who posted (Relate) these messages. I want to count the number of messages sent by each user.

His group messages by sender ID and counting the number of messages per user.

Here is what I still have ...

START n=node(*) MATCH (u:User)-[r:Posted]->(m:Message)
RETURN u, r, count(r)
ORDER BY count(r)
LIMIT 10
+6
source share
1 answer

How about this?

MATCH (u:User)-[r:POSTED]->(m:Message)
RETURN id(u), count(m)
ORDER BY count(m)

Did you have the opportunity to check your current reference card?

https://neo4j.com/docs/cypher-refcard/current/

EDIT:

, :POSTED , -

MATCH (u:User {name: 'my user'})
RETURN u, size((u)-[:POSTED]->())

, Message.

+10

Source: https://habr.com/ru/post/1568069/


All Articles