Neo4j assign rank based on user score

162 Views Asked by At

I have student node with marks. I need to display rank, username and marks. But I am storing username, marks in the database. I have tried following

MATCH (s:student) WHERE s.marks > 70 RETURN s.marks as marks, s.uasername as name ORDER BY s.marks DESC

Output is

    marks   |  name
-------------------------
    95         user1
    94         user2
    93         user3
    93         user4

So here i want rank 3 for both user3, user4.

    marks   |  name    | rank
--------------------------------
    95         user1      1
    94         user2      2
    93         user3      3
    93         user4      3

Any suggestion.

1

There are 1 best solutions below

1
On

You could group them by marks, then the order of your result represents the ranks.

MATCH (s:student) WHERE s.marks > 70 
RETURN s.marks as marks, colleect(s.username) as names 
ORDER BY s.marks DESC