How can I count the number of relationships each node has in Cypher?

Graham Perich

I am using a graph db (neo4j) and cypher. My goal for this query is to first match every Pin that a given User has PINNED, and then count the number of LIKES each of those pins has. Currently I am able to return the total number of likes between all the pins, but this information doesn't help me when there are several pins. For example, if I run this query in my DB right now and there are 2 nodes with 2 likes and 3 likes respectively, my query will return "5". So I have no way of knowing how many of the likes belong to each pin. How can I write this query such that I get the number of LIKES for each pin?

MATCH (u:User {lastName:"Example"})-[:PINNED]->(z:Pin)
WITH collect(z) as cs
MATCH (:User)-[:LIKES]->(y:Pin)
WHERE (y) in cs
MATCH (a:User)-[r:LIKES]->(y)
RETURN COUNT(r), y
InverseFalcon

Looks like you're going a little overboard on matches, we can simplify this.

MATCH (u:User {lastName:"Example"})-[:PINNED]->(z:Pin)
RETURN z, SIZE( ()-[:LIKES]->(z) ) as likes

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I do count on number of occurrences of each distinct value of a column in PostgreSQL?

How to group and count relationships in cypher neo4j

How can I count across several relationships in django

How do i get number of same relationships between two nodes with Cypher

How can I count the number of times one item has been grouped together with another in R?

How can I count the number of unique pairs in a table that has a recursive relationship?

How can I assign a node property value to a variable in Cypher?

How can I count the number of columns a value has after a Where?

How can I include a list of relationships specific to each node returned in the unwind block, in a Neo4j cypher query?

How can I produce a count on the number of times each word has occurred in the following

How can I count the number of comments and likes that a post has in MySQL?

How can i count exams for each category

SQL How can I count the number of meetings for each client?

How can I count the number of rows within each group using SQL?

How can I get the count of consecutive positive number in each column in 2 dimensional df in python/ Padas

Rails: How can I count the total number of contacts a user has when "Contact" is polymorphic?

Neo4j/CYPHER: How can I query some properties from a node, its relationships and target node efficiently?

CYPHER store order of node relationships of the same label when I create

How can I count the result of a for each loop?

How can I count the number of

How can I count the number of messages in one channel of each user?

How can I create all has_one relationships automatically?

How Can I count the number of Capital Cities within each Continent?

How can I limit the number of changes that can be changed with a set in Cypher?

How can I count the number of list items for each unordered list in jquery

How can i count number of records in last 30 days for each user per row in pyspark?

how I can count the number of positive value in each column?

Count of distinct relationships for each node in cypher

How can I delete relationships belonging to a node using Cypher in Memgraph?