2016-06-08 31 views
2

下面的查詢獲取特定用戶的所有組則 放鬆對每個結果(每組),並應刪除所有傳入的關係,只有當計數關係到該組是迭代與UNWIND刪除關係1.如何同時使用暗號

example: group1<-user1 (will delete the incoming relationship to the group) 

     group1-<user1 
     group1-<user2 (will remain all incoming relationships to the group) 

可以協助完成嗎?

MATCH (me:userId{{1})-[rel:relation_group]-(allGroups:GROUP) 
unwind userGroups as group 
//how to use CASE or WHERE in order to check if this group 
has only 1 relationship just remove it 

謝謝。

回答

3

可以在WHERE使用size,例如:

MATCH (me:userId{{1})-[rel:relation_group]-(allGroups:GROUP) 
WHERE size((allGroups)<-[:relation_group]-()) = 1 
DELETE rel 

你並不需要迭代,默認情況下,比賽結束後的後續條款將在本場比賽中的每一行執行,因此,讓我們說第一MATCH返回如下:

me  rel  allGroups 
1  rel3  node5 
1  rel4  node6 

然後DELETE將第一行被執行,然後第二行,等等

+0

但你如何在每個組上迭代這種方式?因爲你會得到組的列表,並且需要檢查每一個,如果傳入關係的數量是1,則刪除它,否則保留它 – rayman

+0

您不需要迭代,只需在WHERE子句 –

+0

中將模式添加到模式即可工作。可以解釋的訣竅?:) – rayman