neo4j查询语句

摘要:
match-[re:reasoning condition]-˃其中p p='FEV1%pred',p p Value='˂30%'WITH,re,qmatch其中。name='qwe'WITH,re,qmatch-[re2:推荐方案]-˃其中q.name='first'WITH、re,q,re2,cmatch-[re 3:方案详细信息]-˃return,re,q、re2,c,re3,D15。查询限定节点的idmatchwhere。name=“***”和p。value='***'returnid16.直接连接关系节点以执行多级查询匹配-[re1]-˃-[re2]-˃returnna,re1,nb,re2,nc17。您可以将查询结果分配给变量,然后返回matchdata=-[re1]-˃-[re2]-˃returndata18。可变长度路径检索由:[*N...]-˃表示:路径长度的最小值为3,起始节点为a,终止节点为b-[*]-˃:表示无限路径长度。起始节点是a,结束节点是b;19.Cypher重复查询结果:match-[re]-˃where-re。name<>“and”return different(注:栗子中的<>是Cypher中的一种操作

一:查询

比较操作:

=
<>
<
>
<=
>=

布尔操作:

AND
OR
NOT
XOR

1、把节点的前两个字为"提示"的节点去除"提示":

match(l) where l.name=~'提示.*' 
with collect(l.name)
as result 
unwind result as row 
return substring(row,2)

2、把带提示的节点,更新为不带提示:

match(l) where l.name=~'提示.*' 
with collect(l.name)
as result 
unwind result as row 
match(h) where h.name=row set h.name=substring(row,2)
return h

 3、分组查询,每个标签的数目,按名字的数目倒排

match(l) 
with collect(l.name) as collectName
unwind collectName as p
return p,count(*)as num order by num desc

 4.查询不存在emergency属性的疾病

match(d:Disease) where not exists (d.emergency) return d.name

 5.查询Condition标签中包含"任二"的节点

match(c:Condition) where c.name contains "任二" return c.name

6.查询疾病没有high_risk属性的节点

match(d:Disease) where d.high_risk is NULL return d.name

 7.更新标签名

MATCH (n:User) REMOVE n:User set n:Person RETURN n

8.更新关系名

MATCH (n:User {name:"foo"})-[r:REL]->(m:User {name:"bar"})
CREATE (n)-[r2:NEWREL]->(m)
SET r2 = r
WITH r
DELETE r

 9.其他

1.如何找到一个节点x,x以某种关系同时连接两个不同节点a和b
match (a)-[r:relation]->(x)<-[r:relation]-(b) return x

2.如何找到节点a和b之间的最短路径
(1)match p=shortestpath((a)-[r:relation]-(b)) return nodes(p)
(2)match(n:na{name:’###’}),(m:nb{name:’###’})with n,m match p=shortestpath((n)-[r*…]-(m)) return p;

3.如何找到节点a和b之间以某种关系相连接的最短路径
p=shortestpath((a)-[r:relationname]->(b)) return nodes(p)

4.找到数据库中出现的唯一节点标签
match n return distinct labels(n)

5.找到数据库中出现的唯一关系类型
match n-[r]-() return distinct type(r)

6.找到数据库中的唯一节点标签和唯一关系类型
match n-[r]-() return distinct labels(n),type(r)

7.找到不与任何关系(或某种关系)向连的节点
start n = node() match n-[r:relationname]-() where r is null return n

8.找到某个带有特定属性的节点
start n=node() match n where has (n.someproperty) return n

9.找到与某种关系相连接的全部节点
start n= node() match n-[r:relationshipname]-() return distinct n

10.找到节点和它们的关系数,并以关系数目降序排列显示
start n=node() match n-[r]-() return n,count(r) as rel_count order by rel_count desc

11.返回图中所有节点的个数
start n = node() match n return count(n)

12.(1)删除图中关系:start n=node(*) match n-[r]-() delete r
(2)删除图中节点:start n =node(*) match n delete n
(3)删除图中所有东西:match (n) detach delete n

13.查询某类节点下某属性为特定值的节点
match (n:person)where n.name=”alice” return n

14.with
Cypher中的With关键字可以将前步查询的结果作为后一步查询的条件,这个在我的工作中可是帮了大忙哈哈。下面是两个栗子。
(1)match(p:node_se)-[re:推理条件]->(q:node_se) where p.name=‘FEV1%pred’and p.value=’<30%’ WITH p,re,q match (q:node_se) <-[re2:推理条件]- (c:node_se)return p, re,q,re2,c
(2)match(p:node_patient)-[re:个人情况]->(q:node_se) where p.name=‘qwe’ WITH p,re,q match (q:node_se) -[re2:推荐方案]-> (c:node_se) where q.name=‘first’ WITH p, re,q,re2,c match (c:node_se)-[re3:方案细节]->(d:drugs) return p, re,q,re2,c,re3,d

15.查询符合条件的某个节点的id
match(p) where p.name = ‘***’ and p.value = ‘***’ return id(p)

16.直接连接关系节点进行多层查询
match(na:bank{id:‘001’})-[re1]->(nb:company)-[re2]->(nc:people) return na,re1,nb,re2,nc

17.可以将查询结果赋给变量,然后返回
match data=(na:bank{id:‘001’})-[re1]->(nb:company)-[re2]->(nc:company) return data

18.变长路径检索
变长路径的表示方式是:[*N…M],N和M表示路径长度的最小值和最大值。
(a)-[ *2]->(b):表示路径长度为2,起始节点是a,终止节点是b;
(a)-[ *35]->(b):表示路径长度的最小值是3,最大值是5,起始节点是a,终止节点是b;
(a)-[ *…5]->(b):表示路径长度的最大值是5,起始节点是a,终止节点是b;
(a)-[ *3…]->(b):表示路径长度的最小值是3,起始节点是a,终止节点是b;
(a)-[ *]->(b):表示不限制路径长度,起始节点是a,终止节点是b;

19.Cypher对查询的结果进行去重
栗:match(p:node_se)-[re]->(q)where re.name <> ‘and’ return distinct(re.name)
(注:栗子中的<>为Cypher中的操作符之一,表示‘不等于’)

20.更新节点的 labels
Neo4j中的一个节点可以有多个 label,返回所有节点的label:match (n) return labels(n)
修改节点的 label,可以先新加 label,再删除旧的label
match (n:label_old) set n:label_new remove n:label_old
match(n:label_new) return labels(n)

21.更新节点的属性
match(n:) set n.new_property = n.old_property remove n.old_proerty

22.根据关系模糊查询
match(d:医保手术和操作名称)-[r]->(l) where type(r)=~'医保手术和操作名称禁忌.*'  return d.name,type(r),collect(l.name)

23.如果找到就设置属性,没找到创建节点并设置属性

  merge on create on match:

  merge (keanu:Person {name:"Keanu"}) on create set keanu.created=timestamp() on match set keanu.lastSeen=timestamp() return keanu;

  24.merge 上使用唯一性约束

  CREATE CONSTRAINT ON (n:Person) ASSERT n.name IS UNIQUE; 


25。去除开头的空格
match (n) where n.name=~' .*' set n.name=substring(n.name,1) return n.name,size(n.name)

免责声明:文章转载自《neo4j查询语句》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇针对IE浏览器里面CSS的Bug解决方法Windows版本sed工具下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

re库的使用

一、re库的调用 import re 二、正则表达式类型 raw string类型(原生字符串类型,即不包括转义符类型):r'text' string类型,更繁琐。 三、Re库主要功能函数 函数              说明 re.search()        在一个字符串中搜索匹配正则表达式的第一个位置,然后返回match对象 re.match(...

ets学习

http://diaocow.iteye.com/blog/1768647 http://www.cnblogs.com/me-sa/archive/2011/08/11/erlang0007.html ets是什么? ets是Erlang Term Storage的缩写,它是一个基于内存的KV Table,支持大数据量存储以及高效查询. ets有4种类型...

《Linux总线、设备与驱动》USB设备发现机制

说明:本分析基于mstar801平台Linux2.6.35.11内核,其他内核版本仅供参考。 一、程序在内核中的位置 1.usb host做为pci总线下的一个设备存在(嵌入式系统中有可能也会直接挂在CPU上);这部分驱动由厂家实现,本分析以mstar为例。 2.USB总线驱动 kernel/drivers/usb/core/driver.c [cp...

谷歌提高Google Assistant中Voice Match的准确性

谷歌正在提高 Google Assistant 中 Voice Match 的准确性,使其变得更加完善。谷歌表示一旦用户在 Google Assistant 中启用 Voice Match 功能,那么可以使用“Hey Google”热词更丰富的句子,例如“Hey Google,播放我的健身歌曲清单”。  Voice Match 允许用户说出“Ok Goog...

编译内核启用iptables及netfilter

在Network Packet Filtering Framework(Netfilter)一节中还有两个额外的配置节——Core Netfilter Configuration(核心Netfilter配置)和IP:Netfilter Configuration(IP:Netfilter配置)。 1. 核心Netfilter配置 核心Netfilter配置...

彻底搞定Android开发中软键盘的常见问题

软键盘显示的原理 软件盘的本质是什么?软键盘其实是一个Dialog。 InputMethodService为我们的输入法创建了一个Dialog,并且将该Dialog的Window的某些参数(如Gravity)进行了设置,使之能够在底部或者全屏显示。当我们点击输入框时,系统对活动主窗口进行调整,从而为输入法腾出相应的空间,然后将该Dialog显示在底部,或...