cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to return the node with most relationships

q6qgs
Node Link

Hi,

Based on my example below, i wanted to return list of user stories (US1 and US2) ordered by the number of tickets related to it that is also linked SP1. In other words, find me userstories (starting) with greatest number of tickets linked to SP1.

this is query I've got right now:

MATCH (:Sprint{id:"SP1"})<-[:SPRINT_TASK]-(:Ticket)-[:SUB_TASK]->(rec:UserStory)
WITH rec, COUNT(*) AS num ORDER BY num DESC 
RETURN rec

Any help will is greatly appreciated 🙂

1 ACCEPTED SOLUTION

intouch_vivek
Graph Steward

Try this

MATCH (:Sprint{id:"SP1"})<-[:SPRINT_TASK]-(:Ticket)-[r1:SUB_TASK]->(rec:UserStory)
WITH rec, COUNT(r1) AS num ORDER BY num DESC
RETURN rec,num

View solution in original post

2 REPLIES 2

MATCH (:Sprint{id:"SP1"})<-[:SPRINT_TASK]-(:Ticket)-[:SUB_TASK]->(rec:UserStory)
WITH rec, COUNT(*) AS num ORDER BY num DESC
RETURN rec, num

This will return two nodes US1 and US2 . If you click "Table" button on the left side of the output, you will get what you want.

If you don't like this, try below

If you have declared your node as (:UserStory{ name : "US1" }) ,try

MATCH (:Sprint{id:"SP1"})<-[:SPRINT_TASK]-(:Ticket)-[:SUB_TASK]->(rec:UserStory)
WITH rec, COUNT(*) AS num ORDER BY num DESC 
RETURN rec.name,num

Hope this helps you.

intouch_vivek
Graph Steward

Try this

MATCH (:Sprint{id:"SP1"})<-[:SPRINT_TASK]-(:Ticket)-[r1:SUB_TASK]->(rec:UserStory)
WITH rec, COUNT(r1) AS num ORDER BY num DESC
RETURN rec,num