neo4j查询语句
一:查询
比较操作:
=
<>
<
>
<=
>=
布尔操作:
AND
OR
NOT
XOR
1、把节点的前两个字为"提示"的节点去除"提示":
match(l) where l.name=~'提示.*'
with collect(l.name)
as result
unwind result as row
return substring(row,)
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,)
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:Teacher) REMOVE n:Student 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.其他
.如何找到一个节点x,x以某种关系同时连接两个不同节点a和b
match (a)-[r:relation]->(x)<-[r:relation]-(b) return x .如何找到节点a和b之间的最短路径
()match p=shortestpath((a)-[r:relation]-(b)) return nodes(p)
()match(n:na{name:’###’}),(m:nb{name:’###’})with n,m match p=shortestpath((n)-[r*…]-(m)) return p; .如何找到节点a和b之间以某种关系相连接的最短路径
p=shortestpath((a)-[r:relationname]->(b)) return nodes(p) .找到数据库中出现的唯一节点标签
match n return distinct labels(n) .找到数据库中出现的唯一关系类型
match n-[r]-() return distinct type(r) .找到数据库中的唯一节点标签和唯一关系类型
match n-[r]-() return distinct labels(n),type(r) .找到不与任何关系(或某种关系)向连的节点
start n = node() match n-[r:relationname]-() where r is null return n .找到某个带有特定属性的节点
start n=node() match n where has (n.someproperty) return n .找到与某种关系相连接的全部节点
start n= node() match n-[r:relationshipname]-() return distinct n .找到节点和它们的关系数,并以关系数目降序排列显示
start n=node() match n-[r]-() return n,count(r) as rel_count order by rel_count desc .返回图中所有节点的个数
start n = node() match n return count(n) .()删除图中关系:start n=node(*) match n-[r]-() delete r
()删除图中节点:start n =node(*) match n delete n
()删除图中所有东西:match (n) detach delete n .查询某类节点下某属性为特定值的节点
match (n:person)where n.name=”alice” return n .with
Cypher中的With关键字可以将前步查询的结果作为后一步查询的条件,这个在我的工作中可是帮了大忙哈哈。下面是两个栗子。
()match(p:node_se)-[re:推理条件]->(q:node_se) where p.name=‘FEV1%pred’and p.value=’<%’ WITH p,re,q match (q:node_se) <-[re2:推理条件]- (c:node_se)return p, re,q,re2,c
()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 .查询符合条件的某个节点的id
match(p) where p.name = ‘***’ and p.value = ‘***’ return id(p) .直接连接关系节点进行多层查询
match(na:bank{id:‘’})-[re1]->(nb:company)-[re2]->(nc:people) return na,re1,nb,re2,nc .可以将查询结果赋给变量,然后返回
match data=(na:bank{id:‘’})-[re1]->(nb:company)-[re2]->(nc:company) return data .变长路径检索
变长路径的表示方式是:[*N…M],N和M表示路径长度的最小值和最大值。
(a)-[ *]->(b):表示路径长度为2,起始节点是a,终止节点是b;
(a)-[ *…]->(b):表示路径长度的最小值是3,最大值是5,起始节点是a,终止节点是b;
(a)-[ *…]->(b):表示路径长度的最大值是5,起始节点是a,终止节点是b;
(a)-[ *…]->(b):表示路径长度的最小值是3,起始节点是a,终止节点是b;
(a)-[ *]->(b):表示不限制路径长度,起始节点是a,终止节点是b; .Cypher对查询的结果进行去重
栗:match(p:node_se)-[re]->(q)where re.name <> ‘and’ return distinct(re.name)
(注:栗子中的<>为Cypher中的操作符之一,表示‘不等于’) .更新节点的 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) .更新节点的属性
match(n:) set n.new_property = n.old_property remove n.old_proerty
neo4j查询语句的更多相关文章
- Neo4j查询语句总结
最近一直在做图数据库的相关工作,对neo4j的查询语言Cypher使用较多,故在此总结记录.Cypher作为图数据库的查询语言,感觉和关系型数据库的查询语言sql差不多吧. 1.如何找到一个节点x,x ...
- Neo4j:图数据库GraphDB(一)入门和基本查询语句
图数据库的代表:Neo4j 官网: http://neo4j.com/ 引言:为什么使用图数据库 在很多新型项目中,应用图数据库已经是势在必行的趋势了,因为图数据库可以很好的表示各种节点与关系的概念 ...
- neo4j - 查询效率的几种优化思路
最近在公司实习做的就是优化neo4j图形数据库查询效率的事,公司提供的是一个在Linux上搭建且拥有几亿个节点的数据库.开始一段时间主要是熟悉该数据库的一些基本操作,直到上周才正式开始步入了优化数据库 ...
- SQL Server-简单查询语句,疑惑篇(三)
前言 对于一些原理性文章园中已有大量的文章尤其是关于索引这一块,我也是花费大量时间去学习,对于了解索引原理对于后续理解查询计划和性能调优有很大的帮助,而我们只是一些内容进行概括和总结,这一节我们开始正 ...
- thinkphp中的查询语句
<?php namespace Admin\Controller; use Think\Controller; class MainController extends Controller { ...
- Oracle 查询语句(where,order by ,like,in,distinct)
select * from production;alter table production add productionprice number(7,2); UPDATE production s ...
- 45 个非常有用的 Oracle 查询语句
这里我们介绍的是 40+ 个非常有用的 Oracle 查询语句,主要涵盖了日期操作,获取服务器信息,获取执行状态,计算数据库大小等等方面的查询.这些是所有 Oracle 开发者都必备的技能,所以快 ...
- mysql查询语句select-子查询
1 子查询定义 在一个表表达中可以调用另一个表表达式,这个被调用的表表达式叫做子查询(subquery),我么也称作子选择(subselect)或内嵌选择(inner select).子查询的结果传递 ...
- mongodb的查询语句学习摘要
看了些资料,对应只需要知道怎么查询和使用mongodb的我来说,这些足够啦. 左边是mongodb查询语句,右边是sql语句.对照着用,挺方便. db.users.find() select * fr ...
随机推荐
- nmcli简单使用
nmcli connection 查看所有网卡信息 nmcli connection show ens33 查看网卡具体信息 nmcli connection reload 是配置文件生效
- Python 编程入门
我喜欢直接了当, 这次主要是推荐蟒营大妈的 Python 入门课(https://py.101.camp), 还有不到一周就要开课了, 欢迎转发推荐~ 点击"夏日大作战:从小白到小能手的 P ...
- 1181: 零起点学算法88——偶数求和(C语言)
一.题目: 题目来源WUSTOJ 二.源代码: #include<stdio.h> int main() { int n, m, num, sum, i, j, k; while (sca ...
- Linux查询命令帮助信息(知道)
方法一 command --help 方法二 man command 操作涉及到的按键: 空格键:显示手册的下一屏 Enter键:一次滚动手册的一行 b:回滚一屏 f:前滚一屏 q:退出 结果基本上全 ...
- go http简单的表单处理
//表单处理 package main import ( "net/http" "io" "fmt" &qu ...
- IDEA好用插件推荐
Maven Helper:排查maven依赖冲突神器,强力推荐! Alibaba Java Coding Guidelines:阿里巴巴编程规范 CamelCase:驼峰命名工具,SHIFT + AL ...
- oracle-3-Linux-11g安装-静默安装
oracle下载地址:https://www.oracle.com/database/technologies/112010-linx8664soft.html 系统是最小化安装的Centos7.2 ...
- typeAliasesPackage 属性的作用
applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xm ...
- C# 字符串补位方法
string i=9; 方法1:Console.WriteLine(i.ToString("D5")); 方法2:Console.WriteLine(i.ToString().Pa ...
- 效率提升工具Listary
效率提升工具Listary https://baijiahao.baidu.com/s?id=1590032175308204846&wfr=spider&for=pc