cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Find max duration in each group

I want to find the max duration in different attribute.
This is my data format.

(:task{WAFERID, duration, FORMLOC, TOLOC})

WAFERID duration FROMLOC TOLOC
A1 10 L1 L2
A1 15 L2 L3
A1 12 L3 L4
B1 9 L1 L2
B1 12 L2 L3
B1 15 L3 L4
C1 9 L1 L2
C1 12 L2 L3
C1 15 L3 L4

Each node records the work of wafer move.
I want to find the longest duration job for each wafer id?
e.g..

WAFERID duration FROMLOC TOLOC
A1 15 L2 L3
B1 15 L3 L4
C1 15 L3 L4
1 ACCEPTED SOLUTION

12kunal34
Graph Fellow

Hi @pawa19961996 ,

Please find below query in your case which will find the max duration.

MATCH(g:task)
WITH g.WAFERID AS ID, collect(m.duration) AS duration
UNWIND duration AS val
RETURN ID, max(val) as max_duration

Please let me know if any other help required.

View solution in original post

5 REPLIES 5

12kunal34
Graph Fellow

Hi @pawa19961996 ,

Please find below query in your case which will find the max duration.

MATCH(g:task)
WITH g.WAFERID AS ID, collect(m.duration) AS duration
UNWIND duration AS val
RETURN ID, max(val) as max_duration

Please let me know if any other help required.

Oh my god Kunal, thanks for your reply it works like a amazing!

But I still don't fully understand how it works.

WITH g.WAFERID AS ID, collect(m.duration) AS duration

Why the duration match the ID?

Thanks again.
Have a nice day!

Or if I want to find the max of each relation.

[rel:chamber_path{time}]

The chamber path will record the move of wafer.

(a:Task)-[:chamber_path]->(Task{FROMLOC: a.FROMLOC})

id WAFERID duration FROMLOC TOLOC
1 A1 10 L1 L2
2 A1 15 L2 L3
3 A1 12 L3 L4
4 B1 9 L1 L2
5 B1 12 L2 L3
6 B1 15 L3 L4
7 C1 9 L1 L2
8 C1 12 L2 L3
9 C1 15 L3 L4

Chamber path

id duration FROM_ID TO_ID
1 10 1 4
2 15 4 7
3 12 2 5
4 9 5 8
5 12 3 6
6 15 6 9

How can I find the max duration in each chamber path?

(a:Task)-[:chamber_path*]->(:Task{FROMLOC:a.FROMLOC)

e.g..

id duration FROM_ID TO_ID
2 15 4 7
3 12 2 5
6 15 6 9

I believe your other question is not clear.
could you please tell us your requirement in better way if possible

and here is an update on the above answer.

MATCH(g: task)
RETURN g.ID, max(g.duration) as max_duration

Thank for your reply.
I found the cypher to query my question.

MATCH(g:Task)-[r:chamber_path]->(b:Task{FROMLOCTYPE:g.FROMLOCTYPE})
WITH g.PPID AS PPID, collect(r.time) AS duration,g.FROMLOCTYPE as FROMLOCTYPE
UNWIND duration AS val
WITH max(val) as max_d,min(val) as min_d,FROMLOCTYPE, max(val) - min(val) as time_different
return min_d,max_d, time_different,PPID,FROMLOCTYPE order by time_different DESC

I use the method similar to searching for nodes.
Thank you very much for your reply.
It really helps me.