如何在 Neo4j db 中找到每部电影收入最高的演员?

发布于 2025-01-13 09:34:23 字数 262 浏览 0 评论 0原文

我需要编写一个查询来查找 Neo4j 数据库中每部电影收入最高的演员。

我写了下面的查询:

match (a:Person)-[role:ACTED_IN]->(m:Movie)
return m.title as Movie, max(role.earnings) as earnings

这给了我电影中的最大收入

如何找到该最高收入对应的演员?

I need to write a query to find the actor having max earnings per movie in Neo4j db.

I have written below query:

match (a:Person)-[role:ACTED_IN]->(m:Movie)
return m.title as Movie, max(role.earnings) as earnings

This gives me the max earning in a movie.

How to find the actor corresponding to that max earning?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过潦 2025-01-20 09:34:23

这里有两种选择。

再次匹配并查找收入最高的演员:

match (a:Person)-[role:ACTED_IN]->(m:Movie)
with m, max(role.earnings) as earnings
match (a:Person)-[:ACTED_IN{earnings:earnings]->(m)
return m.title as Movie, earnings, a.name as actor

排序并取出集合中的第一项:

match (a:Person)-[role:ACTED_IN]->(m:Movie)
with m, role.earnings as earnings, a.name as actor order by earnings
return m.title as Movie, collect(earnings)[0] as earnings, collect(actor)[0] as actor

需要考虑的一些其他问题:

  • 如果两个演员收入相同,您要如何处理?
  • 一名演员可以在同一部电影中扮演多个角色/根据 ACTED_IN 关系获得收入吗?

Here are two alternatives.

Match again and look for the actor/actors that had max earnings:

match (a:Person)-[role:ACTED_IN]->(m:Movie)
with m, max(role.earnings) as earnings
match (a:Person)-[:ACTED_IN{earnings:earnings]->(m)
return m.title as Movie, earnings, a.name as actor

Sort and take first item in collection:

match (a:Person)-[role:ACTED_IN]->(m:Movie)
with m, role.earnings as earnings, a.name as actor order by earnings
return m.title as Movie, collect(earnings)[0] as earnings, collect(actor)[0] as actor

Some additional questions to consider:

  • How do you want to handle if two actors have the same earnings?
  • Can one actor play multiple roles in the same movie/have earnings per ACTED_IN relationship?
虫児飞 2025-01-20 09:34:23

您可以按收入降序排列/收集电影、收入和演员。然后获取集合中的第一项。

MATCH (a:Person)-[role:ACTED_IN]->(m:Movie)
WITH m, role.earnings as earnings, a ORDER BY earnings DESC
RETURN m.title as Movie, collect(earnings)[0] as earnings, collect(a.name)[0] as actor

You can sort/collect the movie, earnings and actor by earnings in descending order. Then get the first item in the collection.

MATCH (a:Person)-[role:ACTED_IN]->(m:Movie)
WITH m, role.earnings as earnings, a ORDER BY earnings DESC
RETURN m.title as Movie, collect(earnings)[0] as earnings, collect(a.name)[0] as actor
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文