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.

Consider a pattern/path only once

Hi all,

In my graph I have the below node-relationship structure :

(Response)-[:isAnswerTo]->(Question)
(Responder)-[:ANSWERED_WITH]->(Response)

Now a Question can be of type multi select i.e. User can select multiple responses as an answer to that question.
So in case I get the below result :

I need to find how many questions have been answered by a responder.
My query :
OPTIONAL MATCH(rs)-[rw:RESPONDED_WITH]->(response)-[:isAnswerTo]->(q)

But this gets both the responses that were selected.
I only need to know if a question was answered or not.

Kindly help.

6 REPLIES 6

Hi @karora7190,

Have you tried with RETURN count(rw) ?

Yes @alexandra I did try count(rw).
The issue with that is that it gives the count as 2 in the case mentioned above.
I want to consider the response only once to get the correct number of questions answered

ameyasoft
Graph Maven
Try this:
// find all the questions that were answered..... 
match (q:Question)-[]->(r:Response)
with q, r

//find count of answered questions per each responder.....
match (u:Responder)-[]->(r)-[]-(q)
return u.name as usr, count(q) as cnt

HI @ameyasoft

Thanks for your response.
I need optional match because i want to get the total questions as well.
I am hoping to get :
total questions : 10
responded : 4

Try this:


// find all the questions that were answered..... 
match (q:Question)-[]->(r:Response)
with q, r

//find count of answered questions per each responder.....
match (u:Responder)-[]->(r)-[]-(q)

//find total questions....
match (q1:Questions)
with count(q1) as TotCnt

return u.name as usr, count(q) as cnt, TotCnt

Thanks for your time @alexandra and @ameyasoft
I was able to get the desired result.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online