当前位置:网站首页>Neo4j: 1. CQL statement
Neo4j: 1. CQL statement
2022-08-08 17:49:00 【my name is 985】
一、Neo4j环境搭建
Neo4jHigh-performance graph database from introductory to practical learning video
neo4j官方下载连接
window傻瓜式安装,点击下一步下一步
Introduction to the homepage interface

二、Neo4j构建的元素
节点
A node represents a concrete entity.
节点可以包含:
一个或多个属性
一个或多个标签
关系
Relationships are used to connect2个节点
Relationships can contain:
一个或多个属性
一个或多个标签
要注意的是:
Relationships are directional,而且有3种情况:one way left、One way to the right、双向.但是neo4jIt seems that the bidirectional relationship is not implemented.To implement a bidirectional relationship in business,It seems to pass2a one-way relationship
标签
类似于java的类的概念,Define a certain type of node or a certain type of relationship.
比如:The label of Zhang's three nodes is person,The label of Li's fourth node is also a person;For example, the label of brotherhood is family,The label of sibling relationship is also family.
Tags can be indexed,So building appropriate tags can improve search speed
语法:
:标签1
:标签1:标签2
比如:CREATE (n:西游记:人物 {name:'张三'}) RETURN n
属性
Both nodes and relationships can have one or more properties.
语法:
{属性key:"属性value", 属性key:"属性value"}
三、CQL
CQL代表Cypher查询语言,The query language used to query the gallery,类比SQLUsed to query relational databases.
| CQL命令 | 用法 |
|---|---|
| CREATE | 创建节点,关系和属性 |
| MATCH | 检索有关节点,关系和属性数据 |
| RETURN | 返回查询结果 |
| WHERE | 提供条件过滤检索数据 |
| DELETE | 删除节点和关系 |
| REMOVE | 删除节点和关系的属性 |
| ORDER BY | 排序检索数据 |
| SET | 添加或更新标签 |
理解CQL
节点(Parentheses indicate nodes)
CQL中,()表示一个节点.比如:(n:person {name:‘如来’})
()表示一个节点
nIndicates an alias for this node
personIndicates that a label is set for this node
{}Indicates what properties to set for this node
关系(Brackets indicate relationships)
CQL中,[]表示一个关系.There must be nodes on both sides of the relationship,And to set the direction,比如
() - [] -> ()
但在neo4j中,A relationship can only have one direction,Cannot point to two nodes at the same time.
But it is allowed that the start node and end node of a relationship are themselves.
CREATE
创建一个节点
# 下面两个是等价的
CREATE ()
CREATE (n)
# 只不过CREATE(n) It is equivalent to giving this node an alias,可以直接RETURN
CREATE (n) RETURN n
# 创建一个节点
CREATE (n:西游记{name: "孙悟空"})
# 一次性创建多个节点
CREATE (n:西游记 {name: "猪八戒"}), (m:西游记 {name: "沙僧"})
创建关系
# 创建新的节点,And at the same time create a relationship for the new node
CREATE (n:`西游记`{name:"唐僧"}) - [r:`坐骑`{attr:"属性"}]-> (m:`西游记`{name:"白龙马"})
return n, m
# between nodes that have already been created,创建1条关系
MATCH (n:`西游记`{name:"孙悟空"}), (m:`西游记`{name:"猪八戒"})
CREATE (n) -[r:师弟{attr:"属性"}]-> (m)
return n, m
# between nodes that have already been created,Create multiple relationships
MATCH (swk:`西游记`{name:"孙悟空"}), (zbj:`西游记`{name:"猪八戒"}), (ss:`西游记`{name:"沙僧"}), (ts:`西游记`{name:"唐僧"})
CREATE (swk) -[:师傅{attr:"属性"}]-> (ts), (zbj) -[:师傅{attr:"属性"}]-> (ts), (ss) -[:师傅{attr:"属性"}]-> (ts)
return swk, zbj, ss
# neo4j,Relationships can point to themselves
MATCH (n:`学习` {name:'张三'})
CREATE (n)-[:自恋]->(n)
RETURN n
DELETE
删除所有节点和关系
MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n,r
或
MATCH (n) DETACH DELETE n
根据idto delete a single node
MATCH (n)
WHERE id(n)=4
DELETE n
RETURN n
根据idto delete a single relationship
MATCH ()-[r]-() Where ID(r)=4 Delete r
根据2node and relationship direction,删除关系
# Build test data
CREATE (:`学习` {name: '张三'}),(:`学习` {name: '李四'}),(:`学习` {name: '王五'});
MATCH (p1:`学习` {name: '张三'}), (p2:`学习` {name: '李四'}), (p3:`学习` {name: '王五'})
CREATE (p1)-[:认识]->(p2)-[:认识]->(p1)-[:认识]->(p3)
RETURN p1,p2,p3
# Delete the relationship between Zhang San and Li Si,Keep Li Si to know Zhang San
MATCH (n:`学习` {name:'张三'}),(m:`学习` {name:'李四'})
OPTIONAL MATCH (n)-[r]->(m)
DELETE r
Also deletes the specified node and its relationship
# Build test data
CREATE (:`学习` {name: '张三'}),(:`学习` {name: '李四'}),(:`学习` {name: '王五'});
MATCH (p1:`学习` {name: '张三'}), (p2:`学习` {name: '李四'}), (p3:`学习` {name: '王五'})
CREATE (p1)-[:认识]->(p2)-[:认识]->(p1)-[:认识]->(p3)
RETURN p1,p2,p3
# Delete Zhang three nodes,At the same time, delete the relationship with Zhang San
MATCH (n:`学习` {name:'张三'})
OPTIONAL MATCH (n)-[r]-()
DELETE n,r
或
MATCH (n学习` {name:'张三'}) DETACH DELETE n
MATCH
match关键字相当于sql的select
# 相当于select *
MATCH (n)
RETURN n
导入导出
- 导出

- 导入

边栏推荐
- pytorch常用语句
- rv和sv的区别
- 差分信号简述
- Cuda Anaconda tensorflow 版本对应
- Edu Codeforces 103 (div2)
- 记录贴:pytorch学习Part2
- CF803F(容斥原理+莫比乌斯函数)
- Superficial understanding of ports
- Open source summer | I have nothing to do during the epidemic, I made a button display box special effect to display my blog
- Tensorflow教程(二)——基本概念与搭建流程
猜你喜欢

Open source summer | I have nothing to do during the epidemic, I made a button display box special effect to display my blog

R file not found problem

文件传输-FTP使用简介

DSPE-PEG-NH2,DSPE-PEG-amine,474922-26-4,磷脂-聚乙二醇-氨基科研试剂

How to set timed network disconnection to assist self-discipline in win10

CF187C(堆优化BFS)

差分信号简述

什么是服务网格?在微服务体系中又是如何使用的?

【教程2】疯壳·ARM功能手机-测试程序介绍

超越CLIP的多模态模型,只需不到1%的训练数据!南加大最新研究来了
随机推荐
DSPE-PEG-NH2,DSPE-PEG-amine,474922-26-4,磷脂-聚乙二醇-氨基科研试剂
使用train_test_split划分训练数据集、测试数据集
咸阳广发证券股票开户安全吗,需要准备什么证件
【目标检测】YOLOv5:标签中文显示/自定义颜色
spark学习笔记(八)——sparkSQL概述-定义/特点/DataFrame/DataSet
The difference between a uri (url urn)
【20210923】Choose the research direction you are interested in?
CF803F(容斥原理+莫比乌斯函数)
Cy5反式环辛烯,TCO-Cy5,Cy5 trans-cyclooctene标记生物分子
DSPE-PEG-Biotin,385437-57-0,磷脂-聚乙二醇-生物素用于生物分子的检测和纯化
手机ETF基金开户哪家证券公司好?哪个更安全
KITTI数据集简介(一)—— 传感器介绍
1dp到底多大!
Detailed explanation of JVM memory model and structure (five model diagrams)
如何让您的wiki内容更高级?
【教程2】疯壳·ARM功能手机-测试程序介绍
How big is 1dp!
开源一夏 | RuntimeException 子类
IP分配——DHCP(讲解+配置)
LeaRun模型驱动开发框架 重塑企业生产力