I have a dataset that looks something like this:
CREATE (n {name:'main', val:3}) -[:r]-> ({name:'sub1', val:2}), (n)-[:r]->({name:'sub2', val:1})
Now, I need to find the maximum value for 'val' for all nodes that are connected to the node named 'main' (including 'main' too). So, in this case the answer is 3.
Since the node named 'main' may not have any subnodes, I used OPTIONAL MATCH
to find the subnodes, then combine all the vals found into a list and call max()
on it, like so:
MATCH (n {name:'main'})
OPTIONAL MATCH (n)-[:r]->(subs)
RETURN max(n.val + collect(subs.val))
But this gives the following error:
Type mismatch: expected Float or Integer but was Collection (line 3, column 18 (offset: 73)) "RETURN max(n.val + collect(subs.val))"
What is the correct may to solve this sort of problem?