Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-09-2022 05:59 AM
I have relations with different values in property and want divide all values by the maximum value and return result as new property for relationship/ How can i do that?
Do I have to first collect all the weight values of all relations, or is it possible somehow easier?
Solved! Go to Solution.
10-30-2022 06:46 PM
Thanks for the answer 🙂
The code almost worked, but I had to remove the "n" after "with"
Working code
match(n:Root)-[r:REL]->(m:Child)
with max(r.value) as maxValue, collect(r) as rels
unwind rels as rel
set rel.scaledValue = rel.value / maxValue
10-09-2022 04:46 PM
You can try something like this:
match(n:Root)-[r:REL]->(m:Child)
with n, max(r.value) as maxValue, collect(r) as rels
unwind rels as rel
set rel.scaledValue = rel.value / maxValue
10-30-2022 06:46 PM
Thanks for the answer 🙂
The code almost worked, but I had to remove the "n" after "with"
Working code
match(n:Root)-[r:REL]->(m:Child)
with max(r.value) as maxValue, collect(r) as rels
unwind rels as rel
set rel.scaledValue = rel.value / maxValue
10-30-2022 07:06 PM
I guess you have multiple Root nodes and you want the max across all the relationships of type REL, regardless of the Root node they are connected too.
Anyways, I am glad you got it to work.
10-09-2022 04:50 PM
As an alternative form, you can also use 'forEach' instead of 'unwind':
match(n:Root)-[r:REL]->(m:Child)
with n, max(r.value) as maxValue, collect(r) as rels
forEach(rel in rels |
set rel.scaledValue = rel.value / maxValue
)
All the sessions of the conference are now available online