simple double match

MATCH (p:Professor)<-[:STUDENT_OF]-(s:Student)
WITH p, avg(s.grade) as grade
MATCH (p:Professor)<-[:STUDENT_OF]-(s:Student)
WHERE s.grade > grade
RETURN p,collect(s) as students


better collect + filter

MATCH (p:Professor)<-[:STUDENT_OF]-(s:Student)
WITH p, avg(s.grade) as grade, collect(s) as all_students
RETURN p,[s IN all_students WHERE s.grade > grade] as students



> Am 25.08.2016 um 13:04 schrieb Sumit Neelam <sumitknee...@gmail.com>:
> 
> 
> Hi,
> 
> I am new to Neo4j and Cypher. I want to write a query for getting following 
> information:
> 
> Graph Description: Sample graph schema image is attached in this post with 
> properties of each node. Graph contains Professor nodes (labeled with P) and 
> student nodes (labeled with S). Professor nodes are connected to their 
> student nodes with edge having 'student' label. All students of same 
> professor form a group.
> 
> Professor nodes properties:
> name
> Student nodes properties:
> name
> grade
> Query: I want to find professors and their students who have grade greater 
> than average grade of their group.
> 
> Example:
> 
> Students' grades avg. for professor P1 group = (7.0+8.0)/2 = 7.5  
> S2 has grade greater than 7.5.
>    
> Students' grades avg. for professor P2 group = (4.0+8.0+9.0)/3 = 7.0
> S4 and S5 have grade greater than 7.0.
> 
> Final output should be like this:
> 
> P1, S2, 8.0
> P2, S4, 8.0
> P2, S5, 9.0
> 
>  
> <https://lh3.googleusercontent.com/-QhdOqT8h02k/V77QBM6OT9I/AAAAAAAAAJc/goPZCCjMZ9w5pCMG6QOGc81kT1uTOhGCACLcB/s1600/Diagram1.png>
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to neo4j+unsubscr...@googlegroups.com 
> <mailto:neo4j+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to neo4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to