好的,所以一位同事帮我解决了这个问题(在我把头撞在桌子上一天半之后)。通过使用 UNION ALL,我得到了我想要的结果。我必须做两个不同的查询;一种关系为空,一种关系不为空。
START n=node(*) MATCH (n:user)-[r?]-(m) WHERE r IS NOT NULL RETURN n, labels(n), type(r), labels(m) as i, m.name as a
UNION ALL
START n=node(*) MATCH (n:user)-[r?]-(m) WHERE r IS NULL RETURN n, labels(n), type(r), null as i, null as a;
这是结果......
==> +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
==> | n | labels(n) | type(r) | i | a |
==> +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | ["context"] | "vinniecontext" |
==> | Node[2558]{lastName:"b",mobilePhone:"b",status:"b",email:"b",name:"b",firstName:"b"} | ["user"] | <null> | <null> | <null> |
==> | Node[2559]{lastName:"c",mobilePhone:"c",status:"c",email:"c",name:"c",firstName:"c"} | ["user"] | <null> | <null> | <null> |
==> | Node[2560]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | <null> | <null> | <null> |
==> | Node[2561]{lastName:"b",mobilePhone:"b",status:"b",email:"b",name:"",firstName:"b"} | ["user"] | <null> | <null> | <null> |
==> | Node[7638]{lastName:"afdasdfasdf",mobilePhone:"asdfa",status:"asdfasdf",email:"asdfasdfasdf",name:"asdfasdfa",firstName:"asdfasdfas"} | ["user"] | <null> | <null> | <null> |
==> | Node[7639]{lastName:"asddsafsda",mobilePhone:"asdfasdfdsa",status:"sadfsadfsda",email:"sadfasdfas",name:"sdafasdfsadf",firstName:"sadfsadfsad"} | ["user"] | <null> | <null> | <null> |
==> +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
我希望这个解决方案可以减轻其他人的痛苦。