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.

Hi @karora7190,

Have you tried with RETURN count(rw) ?

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

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

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

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

1 Like
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