Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j cypher query to combine results

Tags:

neo4j

cypher

Using the Neo4j's console, I have the following graph

enter image description here

I'm trying to query the graph to get 2 rows, 1 for each player, but this is what I have

enter image description here

How to combine the rows such that for Player 36, I only get 1, with a collection of Season and each Season has a collection of Month.

like image 518
mbmc Avatar asked Oct 14 '25 16:10

mbmc


1 Answers

Here is a solution that I think satisfies your requirement. This just takes your query and adds an interim step of aggregating the season and the months together in a map as a season. Then it collects the new compound season into seasons per player.

match (p:Player)-->(s:Season)-->(m:Month)
with p, {season: s, months: collect(m)} as season
return p, collect(season) as seasons

edit: applied cybersam's sage advice

like image 159
Dave Bennett Avatar answered Oct 18 '25 04:10

Dave Bennett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!