Neo4j系列:Cypher(CQL)学习

本文介绍了Neo4j的Cypher查询语言,包括Match、Where和Create等关键概念。Cypher用于操作图数据库,涉及节点和关联的增删改查。通过Match查询节点和关系,Where进行条件过滤,Create则用于创建新的数据。了解这些基础,能帮助初学者更好地掌握Neo4j的数据操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Cypher语言是在学习Neo4j时用到数据库操作语言(DML),涵盖对图数据的增删改查

neo4j数据库简单除暴理解的概念:

Neo4j中不存在表的概念,只有两类:节点(Node)和关联(Relation),可以简单理解为图里面的点和边。
在数据查询中,节点一般用小括号(),关联用中括号[]。
当然也隐含路径的概念,是用节点和关联表示的,如:(a)-[r]->(b),表示一条从节点a经关联r到节点b的路径。

http://codingisforeveryone.com.au/wp-content/uploads/2018/07/Neo4j-Cypher-Quick-Reference-v2018-PART-1.pdf

http://codingisforeveryone.com.au/wp-content/uploads/2018/07/Neo4j-Cypher-Quick-Reference-v2018-PART-2.pdf

http://codingisforeveryone.com.au/wp-content/uploads/2018/08/Neo4j-Cypher-Quick-Reference-v2018_2-Part-3.pdf

1、Match

查找全部节点和关系(2种查询)

match(n) return n

match(n)-->(m) return n,m

MATCH path = () -- () RETURN path

查找节点  ( )

match(a:person) where a.name='Keanu Reeves' return a

查找关系  [ ] 

以下关系都是合法的:

( ) -- ( )           ( ) -> ( )             ( ) <-- ( )

( ) - [ ] - ( )      ( ) - [ ] -> ( )       ( ) <- [ ] - ( )

(4种查询):找到”Keanu Reeves“出演的所有电影

match(a:person)-[r:ACTED_IN]-(b:movie) where a.name='Keanu Reeves' return a,b,r
//a 和 b 是变量,保存节点   r 是变量,保存关系

match(a:person{name:'Keanu Reeves'})-[:ACTED_IN]->(b:movie) return a,b
//a 和 b 是变量,保存节点

match(a:person{name:'Keanu Reeves'})-->(b) return a,b
//a 和 b 是变量,保存节点

match path = (:Character{name:"Aggo"})--(:Character) return path
//path 是变量,保存路径

查找没有关系的节点

match (n) where not (n)–-() return n

2、Where

match(a:person) where a.name<>'Keanu Reeves' return a

match(a:person)-[r:ACTED_IN]-(b:movie) where a.name<>'Keanu Reeves' return a,b,r

3、create

create(hugo:person{name:'Hugo Weaving'}) return hugo

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值