cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β 

Head's Up! Site migration is underway. Pause, resolving how to handle anonymous content

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

jaini_kiran
Node Clone
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