我需要计算具有特定属性的两个节点之间的连接数 [英] I need to count the number of connection between two nodes with a certain property

查看:79
本文介绍了我需要计算具有特定属性的两个节点之间的连接数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库包含有关学院奖提名的信息.

My database contains informations about the nominations for the accademy awards.

我想知道有多少位导演多次获得最佳导演"奖.

I want to know how many directors have won an oscar for "best director" more than one time.

我不能完全达到我想要的结果,一个被提名人​​的名单. 我最近去过的地方是这个查询:

I can't quite get to the result that i want, a list of nominees. The closest I've been is with this query:

MATCH (n:Nominee)-[n1:NOMINATED]->(c:Category)
WHERE c.name="Best Director" AND n1.win=true
RETURN count(n1.win), n.name
ORDER BY n.name;

wich返回导演姓名和获得奥斯卡奖的次数.

wich returns the directors names and the number of times they won an oscar.

我试图做类似

MATCH (n:Nominee)-[n1:NOMINATED]->(c:Category)
WHERE c.name="Best Director" AND n1.win=true AND count(n1.win)>1
RETURN n.name;

但出现错误提示

在这种情况下无效使用聚合函数count(...)(第 2,第50列(偏移量:96))"WHERE c.name ="Best Director" AND n1.win = true AND count(n1.win)> 1"

Invalid use of aggregating function count(...) in this context (line 2, column 50 (offset: 96)) "WHERE c.name="Best Director" AND n1.win=true AND count(n1.win)>1"

有人可以帮我吗?

推荐答案

使用

Use WITH to aggregate the wins first. According to the docs:

[...] WITH用于引入聚合,然后可以将其用于WHERE中的谓词.这些聚合表达式在结果中创建新的绑定.与RETURN一样,WITH也可以使用别名作为绑定名称将别名表达式引入结果中.

[...] WITH is used to introduce aggregates which can then by used in predicates in WHERE. These aggregate expressions create new bindings in the results. WITH can also, like RETURN, alias expressions that are introduced into the results using the aliases as binding name.

因此,这样的查询应该起作用:

So a query like this should work:

MATCH (n:Nominee)-[n1:NOMINATED]->(c:Category)
WHERE c.name="Best Director" AND n1.win=true
WITH n, count(n1.win) AS winCount
WHERE winCount > 1
RETURN n.name;

另请参见 WHERE 上的文档:

See also the docs on WHERE:

WHERE将约束添加到MATCH或OPTIONAL MATCH子句中的模式,或过滤WITH子句的结果.

WHERE adds constraints to the patterns in a MATCH or OPTIONAL MATCH clause or filters the results of a WITH clause.

这篇关于我需要计算具有特定属性的两个节点之间的连接数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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