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 can I display count of relationships and list of source node names

I have a fictitious example of students doing test questions
student answers questions either "CORRECT" or "WRONG"

I can find the question that students answered incorrectly most often using:
MATCH (s:Student)-[r:ANSWERED {result: "WRONG"}]->(q:Question)
RETURN q.qId as Question, COUNT(r) as answeredWrong
ORDER BY answeredWrong DESC

This shows me a table such as:

Question answeredWrong
"4" 5
"3" 3
"2" 2
"1" 1
"5" 1

But how can I show a list of students who got that question wrong as part of the tabular results?

1 ACCEPTED SOLUTION

Hi Adam,

I think you could do something like the following (just guessing without knowing the attributes of the node Student):

MATCH (s:Student)-[r:ANSWERED {result: "WRONG"}]->(q:Question)
RETURN q.qId as Question, COUNT(r) as answeredWrong, COLLECT(s.name) as studentsWhoGaveWrongAnswers
ORDER BY answeredWrong DESC

Regards,
Elena

View solution in original post

1 REPLY 1

Hi Adam,

I think you could do something like the following (just guessing without knowing the attributes of the node Student):

MATCH (s:Student)-[r:ANSWERED {result: "WRONG"}]->(q:Question)
RETURN q.qId as Question, COUNT(r) as answeredWrong, COLLECT(s.name) as studentsWhoGaveWrongAnswers
ORDER BY answeredWrong DESC

Regards,
Elena