cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

max property value within a list of nodes

Hi All!

I'm attempting to identify a way to create a relationship between two nodes, based on the value of one of their properties.  If I was to psuedo-code talk it out, it might be something like this:

match the node (n:asset) with a transaction id of "12345" and a secondProperty value of 0 

Also, match  the node (n:asset) with a transaction id of "12345", that has a  secondProperty value that is the largest value of all nodes that have a transaction id of "12345" 

Creation a relationship [:relationship] between these two nodes

 

.... my messy version might be something like:

match (n:asset {transactionId: "12345" , secondProperty: 0})

match (m:asset {transactionId: "12345") where secondProperty = max(secondProperty.value)

create (n)-[r:RELATIONSHIP]->(m)

return n,r,m


I know this is wrong but could use some help righting the ship?  Any thoughts?   I've attempted using the apoc.agg.maxItems function, but I have difficulty following the examples and documentation.

 

-Isaac

1 ACCEPTED SOLUTION

ameyasoft
Graph Maven

Try this:

match (a:Asset) where a.transactionId = "12345"
with min(a.secondProperty) as mn, max(a.secondProperty) as mx

match (b:Asset) where b.secondProperty = mn and b.transactionId = "12345"
match (c:Asset) where c.secondProperty = mx and c.transactionId = "12345"

merge (b)-[:MAX_SECOND_PROPERTY]->(c)

return b, c

View solution in original post

3 REPLIES 3

ameyasoft
Graph Maven

Try this:

match (a:Asset) where a.transactionId = "12345"
with min(a.secondProperty) as mn, max(a.secondProperty) as mx

match (b:Asset) where b.secondProperty = mn and b.transactionId = "12345"
match (c:Asset) where c.secondProperty = mx and c.transactionId = "12345"

merge (b)-[:MAX_SECOND_PROPERTY]->(c)

return b, c

You're a miracle worker.  Thank you so much!   

ameyasoft
Graph Maven

Am glad of some help to you! Thanks for your appreciation.