Problem on the UNWIND clause

Hi,

match (e1:Event {eventType:"event1"})<-[:takePlace]-(c:Car {carID: car_id})-[:takePlace]->(e2:Event {eventType:"event2"})
with collect(distinct e2.start_time) as e2_sts, collect(distinct e1.start_time) as e1_sts

unwind e2_sts as e2_st
match (ex:Event {eventType:"event1"})<-[:takePlace]-(:Car {carID:car_ID}) where ex.start_time < e2_st
with max(ex.start_time) as mx
with collect(mx) as cl
return cl

I have the above query which the problem is focusing on the part after unwind clause. which is I would like to compare with each item in e2_sts and get set of list. Then I wish to take the maximum value in each list and collect the maximum value for each list.

I searched online which the logic is more or less the same, but my code is not working and return me just one value in total which is wrong. So I wish to get some insights from you

Thanks,
oli

you have to use the grouping key in your aggregation too, otherwise you'll get a global aggregation

match (e1:Event {eventType:"event1"})<-[:takePlace]-(c:Car {carID: car_id})-[:takePlace]->(e2:Event {eventType:"event2"})
with collect(distinct e2.start_time) as e2_sts, collect(distinct e1.start_time) as e1_sts

unwind e2_sts as e2_st
match (ex:Event {eventType:"event1"})<-[:takePlace]-(:Car {carID:car_ID}) where ex.start_time < e2_st
RETURN e2_st,  max(ex.start_time) as mx
1 Like