neo4j使用之超神之旅

1.查询整个链路中任意一段的关系类型是“department”的链路数据

MATCH path= (n)-[r1 *0..7 {`relation_type`:'once2once'}]-(m) 
where id(n)=0 and any(x in relationships(path)  where type(x)='department')
return path

效果图:
在这里插入图片描述

2.查询整个链路中最后一段的关系类型是“”的链路数据信息

MATCH path= (n)-[r1 *0..7 {`relation_type`:'once2once'}]-(m)
where id(n)=0 and type(last(relationships(path)))='competition'
return path

效果图:
在这里插入图片描述

3.查询与指定节点有关联的所有关系链数据(链路存在方向)

MATCH (p)<-[r0 *0..6 {`relation_type`:'once2once'}]- (n)<-[r1 *0..6 {`relation_type`:'once2once'}]-(m)-[r2 *0..1 {`relation_type`:'many2many'}]-(o) where id(n)=%s 
 unwind (r0+r1+r2) as rel1 
 with distinct id(rel1) as id,type(rel1) as code, rel1.name as name 
 return code,name,count(id) as num

效果图:
在这里插入图片描述
4.模糊匹配节点属性包含检索字符的数据(忽略大小写)

match (n) where n:mm_yg and(n.name=~'(?i).*柴.*' or n.code=~'(?i).*柴.*' or n.dh=~'(?i).*柴.*')   
RETURN n order by n.name skip 0 limit 10

效果图
在这里插入图片描述
5.检索节点属性是列表时的列表项值包含指定字符的数据

match (n) where n.name=~'(?i).*高.*' and any(x in n.ls where x =~'(?i).*高.*')  return n;

效果图
在这里插入图片描述
6.查找与开始节点最近的带有指定标签的其他节点!!!
全关系图:李四的上级有组织节点,公司节点(百度科技,网易公司都是公司节点)
在这里插入图片描述

执行语句:

查询与李四有关系的其他节点中,最近带有有“mm_company” 标签的公司节点
(第一层 in 是循环链路中的每个节点)
(第二层 in 是循环每个节点上的每个标签,因为每个节点不止一种标签)
(第一个 all 是判断第一个节点,最后一个节点,中间节点都满足条件)
(第二个 all 是判断中间节点,必须都满足每个节点都不包含 “mm_company”标签)

MATCH path= (start)-[r *]->(end:`mm_company`)
WHERE start.name=~'(?i).*李四.*'
with start, end,nodes(path) as path
where all(x in path where (id(x)=id(start)) or (id(x)=id(end))  or (all( la in labels(x) where la<>'mm_company' ) ))
return start,end,path

效果图:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值