如何在Neo4j Cypher中获得具有给定属性的给定数量的出站关系的节点? [英] How to get nodes that have a given amount of outgoing relationships with a given property in Neo4j Cypher?

查看:260
本文介绍了如何在Neo4j Cypher中获得具有给定属性的给定数量的出站关系的节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的域中,节点可以与其他实体具有几种相同类型的关系。每个关系都有多个属性,我想检索通过至少两个呈现给定属性的关系连接的节点。

In my domain a node can have several relationships of the same type to other entities. Each relationship have several properties and I'd like to retrieve the nodes that are connected by at least 2 relationships that present a given property.

EG:节点之间的关系的属性为 year 。如何找到具有至少两个传出关系且设置为 2012 的节点?

EG: A relationship between nodes have a property year. How do I find the nodes that have at least two outgoing relationships with the year set to 2012?

为什么到目前为止 Cypher 查询看起来像这样(语法错误)

Why Chypher query so far looks like this (syntax error)

START x = node(*)
MATCH x-[r:RELATIONSHIP_TYPE]->y
WITH COUNT(r.year == 2012) AS years
WHERE HAS(r.year) AND years > 1
RETURN x;

我也尝试了嵌套查询,但我相信 Cypher 。最接近的是以下内容,但我不知道如何清除具有值1的节点:

I tried also nesting queries but I believe that it's not allowed in Cypher. The closest thing is the following but I do not know how to get rid of the nodes with value 1:

START n = node(*)
MATCH n-[r:RELATIONSHIP_TYPE]->c
WHERE HAS(r.year) AND r.year == 2012
RETURN n, COUNT(r) AS counter
ORDER BY counter DESC


推荐答案

尝试此查询

START n = node(*)
MATCH n-[r:RELATIONSHIP_TYPE]->c
WHERE HAS(r.year) AND r.year=2012
WITH n, COUNT(r) AS rc
WHERE rc > 1
RETURN n, rc

这篇关于如何在Neo4j Cypher中获得具有给定属性的给定数量的出站关系的节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆