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?

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( as studentsWhoGaveWrongAnswers
ORDER BY answeredWrong DESC


1 Like