Neo4j Cypher return most consecutive “passes”

后端 未结 2 997
深忆病人
深忆病人 2020-12-22 07:02

I am trying to return from a graph database the students with the most consecutive passes to a series of exams.

Below is my current code but not sure where I can ta

2条回答
  •  时光说笑
    2020-12-22 07:42

    This is a tricky one, and as far as I know can't be done with just Cypher, but there is a procedure in APOC Procedures that can help.

    apoc.coll.split() takes a collection and a value to split around, and will yield records for each resulting sub-collection. Basically, we collect the ordered results per student, split around failures to get collections of consecutive passes, then get the max consecutive passes from the sizes of those collections:

    MATCH (s:Student)-[r:TAKEN]->(e:Exam)
    WITH s, r.score >= e.pass_mark as passed
    ORDER BY e.date
    WITH s, collect(passed) as resultsColl
    CALL apoc.coll.split(resultsColl, false) YIELD value
    WITH s, max(size(value)) as consecutivePasses
    RETURN s.name as student, consecutivePasses
    

提交回复
热议问题