你想用一个查询做很多事情,但我认为这样做可以:
MATCH (h:Hierarchy {Hierarchy_ID:181,Hierarchy_Name:'Global Property Hierarchy'})
MERGE (h)-[:HAS{status;'ACTIVE'}]->(og:OperatingGroup {OperatingGroup_ID:'NOP',OpeartingGroup_Name:'Operating'})
ON CREATE SET og.GOG_Start_Date = timestamp()
WITH h, og
MATCH (h)-[has:HAS{status:'ACTIVE'}]->(other:OperatingGroup)
WHERE other <> og
SET has.status='INACTIVE'
SET other.GOG_End_Date = og.GOG_Start_Date
RETURN h, og
匹配启动所有内容的 Hierarchy 节点。
MATCH (h:Hierarchy {Hierarchy_ID:181,Hierarchy_Name:'Global Property Hierarchy'})
将其与 ID 为“NOP”的 OperatingGroup 的 Active 状态关系合并。
MERGE (h)-[:HAS{status;'ACTIVE'}]->(og:OperatingGroup {OperatingGroup_ID:'NOP',OpeartingGroup_Name:'Operating'})
如果组刚刚创建,则设置开始日期。
ON CREATE SET og.GOG_Start_Date = timestamp()
现在匹配任何其他存在的操作组及其 HAS 关系。按要求设置 status 属性和 endDate(在 OperatingGroup 节点上,以匹配 GOG_Start_Date?)。
WITH h, og
MATCH (h)-[has:HAS]->(other:OperatingGroup)
WHERE other <> og
SET has.status='INACTIVE'
SET other.GOG_End_Date = og.GOG_Start_Date
RETURN h, og
编辑 - OperatingCompany
我从 Christophe 的回答中看到,他正在保留 OperatingGroup 与 OperatingCOmpany 的关系,虽然没有被要求这样做确实很有意义(我们是否在您的图表上颠倒了操作?)。
MATCH (h:Hierarchy {Hierarchy_ID:181,Hierarchy_Name:'Global Property Hierarchy'})-[existingHas:HAS]->(existingOg:OperatingGroup)<-[belong:BELONGS]-(company:OperatingCompany)
MERGE (h)-[:HAS{status;'ACTIVE'}]->(og:OperatingGroup {OperatingGroup_ID:'NOP',OpeartingGroup_Name:'Operating'})<-[:BELONGS]-(company)
ON CREATE SET og.GOG_Start_Date = timestamp()
WITH h, og, existingHas, exitingOg
SET existingHas.status='INACTIVE'
SET existingOg.GOG_End_Date = og.GOG_Start_Date
RETURN h, og