只有单向关系
CREATE 语句:
创建节点和单双向关系
1 -> 2 -> 5 -> 9
-> 6
-> 3 -> 7 -> 10
-> 4 -> 8
create (zhang1:People{name:'zhang1'})
create (zhang2:People{name:'zhang2'})
create (zhang3:People{name:'zhang3'})
create (zhang4:People{name:'zhang4'})
create (zhang5:People{name:'zhang5'})
create (zhang6:People{name:'zhang6'})
create (zhang7:People{name:'zhang7'})
create (zhang8:People{name:'zhang8'})
create (zhang9:People{name:'zhang9'})
create (zhang10:People{name:'zhang10'})
create (zhang1)-[:FOLLOW]->(zhang2)
create (zhang1)-[:FOLLOW]->(zhang3)
create (zhang1)-[:FOLLOW]->(zhang4)
create (zhang2)-[:FOLLOW]->(zhang5)
create (zhang2)-[:FOLLOW]->(zhang6)
create (zhang3)-[:FOLLOW]->(zhang7)
create (zhang4)-[:FOLLOW]->(zhang8)
create (zhang5)-[:FOLLOW]->(zhang9)
create (zhang7)-[:FOLLOW]->(zhang10)
单向关系
[r:FOLLOW*0..]
即关系从0到无止尽in:
即 a -> b
match p=(a:People) - [r:FOLLOW*0..] -> (b:People) where b.name = 'zhang2' return p
in: 即 a -> b
out:
即 b -> c
match p=(b:People) - [rr:FOLLOW*0..] -> (c:People) where b.name = 'zhang2' return p
out: 即 b -> c
both:
即 a <-> b <-> c
match p=(a:People) <- [r:FOLLOW*0..] -> (b:People) <- [rr:FOLLOW*0..] -> (c:People) where b.name = 'zhang9' return p
both:即 a <-> b <-> c
有单双向关系
CREATE 语句:
创建节点和单双向关系
1 <-> 2 <-> 5 -> 9
-> 6
-> 3 <-> 7 -> 10
-> 4 <-> 8
create (zhang1:User{name:'zhang1'})
create (zhang2:User{name:'zhang2'})
create (zhang3:User{name:'zhang3'})
create (zhang4:User{name:'zhang4'})
create (zhang5:User{name:'zhang5'})
create (zhang6:User{name:'zhang6'})
create (zhang7:User{name:'zhang7'})
create (zhang8:User{name:'zhang8'})
create (zhang9:User{name:'zhang9'})
create (zhang10:User{name:'zhang10'})
create (zhang1)-[:FOLLOW]->(zhang2)
create (zhang1)-[:FOLLOW]->(zhang3)
create (zhang1)-[:FOLLOW]->(zhang4)
create (zhang2)-[:FOLLOW]->(zhang1)
create (zhang2)-[:FOLLOW]->(zhang5)
create (zhang2)-[:FOLLOW]->(zhang6)
create (zhang3)-[:FOLLOW]->(zhang7)
create (zhang4)-[:FOLLOW]->(zhang8)
create (zhang5)-[:FOLLOW]->(zhang2)
create (zhang5)-[:FOLLOW]->(zhang9)
create (zhang7)-[:FOLLOW]->(zhang3)
create (zhang7)-[:FOLLOW]->(zhang10)
create (zhang8)-[:FOLLOW]->(zhang4)
单双向关系
MATCH 语句:
像SQL
语句一样
match (u:User) return u
match (u:User) where u.name='zhang5' return u
match p=(u:User)-[r:FOLLOW]->(uu:User) return p
[r:FOLLOW*0..]
即关系从0到无止尽
in:
即 a -> b
match p=(a:User) - [r:FOLLOW*0..] -> (b:User) where b.name = 'zhang2' return p
in: 即 a -> b
out:
即 b -> c
match p=(b:User) - [rr:FOLLOW*0..] -> (c:User) where b.name = 'zhang2' return p
out: 即 b -> c
both:
即 a <-> b <-> c
match p=(a:User) <- [r:FOLLOW*0..] -> (b:User) <- [rr:FOLLOW*0..] -> (c:User) where b.name = 'zhang9' return p
both:即 a <-> b <-> c
网友评论