我试图做一个棘手的查询。 我需要检查是否存在关系;
该财产可能会消极。
这基本上是我想要的,虽然这种格式不会起作用,因为你在MERGE之后不能有一个WITH语句:
MATCH (n1:Type1 {id:{id1}), (n2:Type2 {id: {id2})
MERGE (n1)-[r:RELATIONSHIP]->(n2) WITH CASE
WHEN r.prop + {val} < 0 THEN 0
ELSE r.prop + {val} END as prop
ON CREATE SET r.prop = prop
ON MATCH SET r.prop = prop
这就是它的两个部分,尽管我不想再查询两次:
MATCH (n1:Type1 {id:{id1}), (n2:Type2 {id: {id2})
MERGE (n1)-[r:RELATIONSHIP]->(n2)
ON CREATE SET r.prop = 0
MATCH (n1:Type1 {id:{id1})-[r:RELATIONSHIP]->n2:Type2 {id: {id2})
WITH r, CASE
WHEN r.prop + {val} < 0 THEN 0
ELSE r.prop + {val} END as prop
SET r.prop = prop
答案 0 :(得分:0)
我认为这个查询应该可以解决问题:
MATCH (n1:Type1 {id:{id1}), (n2:Type2 {id: {id2})
MERGE (n1)-[r:RELATIONSHIP]->(n2)
ON CREATE SET r.prop = 0
ON MATCH SET r.prop =
CASE r.prop
WHEN r.prop + {val} < 0
THEN 0
ELSE r.prop + {val}
END
答案 1 :(得分:0)
MATCH (n1:Type1 {id:{id1}), (n2:Type2 {id: {id2})
MERGE (n1)-[r:RELATIONSHIP]->(n2)
ON CREATE SET r.prop =
CASE
WHEN {val} < 0 THEN 0
ELSE {val}
END
ON MATCH SET r.prop =
CASE
WHEN r.prop + {val} < 0
THEN 0
ELSE r.prop + {val}
END