出现次数最多的一对演员 [英] Pair of Actors with Most Occurences

查看:0
本文介绍了出现次数最多的一对演员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首次尝试使用电影图形示例的Neo4j/Cypher用户。

我想退还一起出演电影次数最多的那对演员。我正在尝试的代码似乎按DESC顺序给了我想要的东西,但我如何将其限制为仅最高强度而不是所有对?

MATCH (n)-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors)
RETURN n.name, coActors.name, count(*) AS Strength ORDER BY Strength DESC

推荐答案

这样的怎么样

// find pairs of actors that acted inthe same movies together
MATCH (n1)-[:ACTED_IN]->(m)<-[:ACTED_IN]-(n2)

// ensure you only get the duo in a single ordered pair
WHERE id(n1) < id(n2)

// order them by the most prolific pairings
WITH n1, n2, count(m) AS strength
ORDER BY strength DESC

// collect all of the duos
WITH collect({actor1: n1.name, actor2: n2.name, strength: strength} ) AS duos

// find the most prolific number from the first element
WITH duos, duos[0].strength AS max_strength

// filter the collection so only those that are the most prolific are returned
RETURN [duo IN duos WHERE duo.strength = max_strength | duo] AS top_duos

这篇关于出现次数最多的一对演员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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