我正在尝试执行以下操作:
初始图表:
查询后的图表:
假设在运行查询之前不存在price属性
这是我提出的,但不知道如何继续。
MATCH (b:Building)
SET b.price =
CASE WHEN has(b.price) THEN b.price
ELSE
// Go to the next level, compute price for all children and assign the sum of children to b.price.
END
RETURN b
答案 0 :(得分:0)
这样的东西?
MATCH (parent:Building)
WHERE not has(parent.price)
match (parent)-->(child)
WITH parent, sum(child.price) as price
SET parent.price = price
MATCH path=(root:Building)-[*0..]->(parent)-->(child)
WITH parent,child, length(path) as l
ORDER BY l desc
WITH parent, sum(child.price) as price
SET parent.price = coalesce( parent.price, price)