# 语法 WHERE <condition> WHERE <condition> <boolean-operator> <condition> # <condition>语法 <property-name> <comparison-operator> <value>
# 布尔运算符 AND OR NOT XOR
# 比较运算符 = <> < > <= >=
# 匹配 MATCH (emp:Employee) WHERE emp.name = 'Abc' RETURN emp
# 使用WHERE子句创建关系 MATCH (<node1-label-name>:<node1-name>),(<node2-label-name>:<node2-name>) WHERE <condition> CREATE (<node1-label-name>)-[<relationship-label-name>:<relationship-name> {<relationship-properties>}]->(<node2-label-name>) MATCH (cust:Customer),(cc:CreditCard) WHERE cust.id = "1001" AND cc.id= "5001" CREATE (cust)-[r:DO_SHOPPING_WITH{shopdate:"12/12/2014",price:55000}]->(cc) RETURN r
DELETE删除<节点和关系>
1 2 3 4 5 6 7 8
# DELETE节点子句语法 DELETE <node-name-list> MATCH (e: Employee) DELETE e
# DELETE节点和关系子句语法 DELETE <node1-name>,<node2-name>,<relationship-name> MATCH (cc: CreditCard)-[rel]-(c:Customer) DELETE cc,c,rel
MATCH (cc:CreditCard) RETURN cc.id as id,cc.number as number,cc.name as name, cc.valid_from as valid_from,cc.valid_to as valid_to UNION MATCH (dc:DebitCard) RETURN dc.id as id,dc.number as number,dc.name as name, dc.valid_from as valid_from,dc.valid_to as valid_to # UNION ALL语法 <MATCH Command1> UNION ALL <MATCH Command2>
MATCH (cc:CreditCard) RETURN cc.id as id,cc.number as number,cc.name as name, cc.valid_from as valid_from,cc.valid_to as valid_to UNION ALL MATCH (dc:DebitCard) RETURN dc.id as id,dc.number as number,dc.name as name, dc.valid_from as valid_from,dc.valid_to as valid_to
# 大写 MATCH (e:Employee) RETURN e.id,UPPER(e.name),e.sal,e.deptno # 小写 MATCH (e:Employee) RETURN e.id,LOWER(e.name),e.sal,e.deptno # 切割<右闭> MATCH (e:Employee) RETURN e.id,SUBSTRING(e.name,0,2),e.sal,e.deptno
聚合函数
1 2 3 4 5 6 7 8
# COUNT MATCH (e:Employee) RETURN COUNT(*) # MAX & MIN MATCH (e:Employee) RETURN MAX(e.sal),MIN(e.sal) # AVG & SUM MATCH (e:Employee) RETURN SUM(e.sal),AVG(e.sal)
关系函数
1 2 3 4 5 6 7 8 9
# 检索开始节点 MATCH (a)-[movie:ACTION_MOVIES]->(b) RETURN STARTNODE(movie) # 检索结束节点 MATCH (a)-[movie:ACTION_MOVIES]->(b) RETURN ENDNODE(movie) # 检索关系的ID和类型详细信息 MATCH (a)-[movie:ACTION_MOVIES]->(b) RETURN ID(movie),TYPE(movie)