条件表达式数据库
CASE test
WHEN value THEN result
[WHEN ...]
[ELSE default]
ENDspaCASE
WHEN predicate THEN result
[WHEN ...]
[ELSE default]
END字符串
match(n:User)
where n.id = 1
return case n.id when 1 then '管理员' else '普通人员' end as resultit
match(n:User)
where n.id = 1
return case when n.id=1 then '管理员' else '普通人员' end as resultio
// 查询全部节点test
match (n)
return n搜索
//节点和属性过滤数据
match (me)
where me.id = 1 and me:User
return me项目
//检查【节点】【属性】的存在性查询
match (me)
where exists(me.age)
return me
//字符串匹配(区分大小写)
match (u)
where u.name starts with 'a' and u.name ends with 'z' or u.name contains 'zs'
return u
// 匹配多种关系中的一种 , 使用 |
match (n) -[r :ORG | :DEP]-> ()
return n
// 返回类型类型
match (n) -[r]- ()
return type(r)
//返回标签类型
match (n:User)
where n.id = 1
return labels(n)
//返回多个类型 【我朋友的朋友】
match (me:User) -->(friend:User) --> (friend_of_friend:User)
return friend_of_friend
可变长关系 -[:TYPE * minHops .. maxHops]->
// 返回 1 至 2 跳的之内的用户
match (me:User{id:1}) -[*1..2]->(n:User)
return n
// 返回 0跳用户,就是返回本身
match (me:User{id:1}) -[*0]->(n:User)
return n
//返回至少有 2跳的用户
match (me:User) -[*2..]-> (n:User) // -[*2..]-> 等于 -[*2]->
return me
//返回小于 2跳的用户, 注意不包含 0跳用户, 若是要包含应该是 -[*0..2]->
match (me:User) -[*..2]->(n:User) // -[*..2]-> 等于 -[*1..2]->
return me
// 返回数据库中节点的id。 注意neo4j 会重用已经删除的节点的id
match (me:User)
where me.id = 3
return id(me)
返回指定用户的全部关系
match (u1:User) -[*]-> (u2:User)
where u1.id = 1 // -[*]-> 表示跳数不限制
return *
match (u1:User) --> (u2:User) where u1.id = 1 return * //只表示返回用户自己,及其1跳的用户
返回找到指定用户,返回跳数大于2的路径
match p=(u1:User)-[*2]->(u2:User)
where u1.id = 1
return p
// 指定两个节点,找出其最短路径
match (u1:User),(u2:User),sp = shortestPath((u1)-[*]->(u2))
where u1.id = 1 and u2.id = 3
return sp
//带断言的最短路径
//全部最短路径
match (u1:User),(u2:User),p = allShortestPaths((u1) -[*]-> (u2) )
where u1.id = 1 and u2.id = 3
return p
//模式过滤,注意 where 中的模式是过滤 match 以后的结果
match (u),(o)
where u.id in [1,2] and not (u)-->(o)
return *
optinal match
用于搜索模式中描述的匹配项,对于找不到的项目用null 代替
match (me:User) where me.id = 32 optional match (me)-->(o) return o