[英]Neo4j: query to find nodes with most relationship
I'm trying to find which movie has the most number of actors in it in my database.Here's what i came up with but it kept giving me blank.我试图在我的数据库中找出哪部电影中演员人数最多。这是我想出的,但它一直给我空白。
MATCH (m:Movie)
WITH m, SIZE(()-[:ACTED_IN]->(m)) as actorCnt
MATCH (a)-[:ACTED_IN]->(m)
RETURN m, a
Maybe you did not wait long enough, because your query is trying to return all the actors for every movie.也许您等待的时间不够长,因为您的查询试图返回每部电影的所有演员。
This query should return a list of the actors for the (single) movie with the most actors:此查询应返回演员人数最多的(单一)电影的演员列表:
MATCH (m:Movie)
WITH m
ORDER BY SIZE(()-[:ACTED_IN]->(m)) DESC
LIMIT 1
RETURN m, [(a)-[:ACTED_IN]->(m)|a] AS actors
It orders the movies by descending number of actors, takes just the first one, and returns it and a list of all its actors.它按演员人数降序排列电影,只取第一个,并返回它和所有演员的列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.