英文:
cypher query without any return rows after modifying it using pattern comprehension
问题
第一个查询在 neo4j 电影数据集上使用了密码查询,将返回 822 行数据:
MATCH (a:Actor)-[:ACTED_IN]->(m:Movie)
WHERE m.year = 2000
AND a.born IS NOT NULL
RETURN DISTINCT a.name AS Actor, a.born AS Born
order by a.born
第二个查询使用了模式推导,但返回了 15443 行数据,但它们全都是空数组。
MATCH (a:Actor)
with a, [ (a where a.born is not null)-[:ACTED_IN]->(m:Movie where m.year = 2000) | a.name ] as Actors
return Actors
第二个查询出现问题的原因是模式推导中的条件不正确。在模式推导中,你试图创建一个演员(Actor)和对应电影年份为 2000 的关联的数组。但是在该查询中,条件和循环似乎被错误地应用,导致每个演员都对应了一个空数组,这导致了返回的结果都是空的。
英文:
This cypher query on the neo4j movie dataset will return 822 rows
MATCH (a:Actor)-[:ACTED_IN]->(m:Movie)
WHERE m.year = 2000
AND a.born IS NOT NULL
RETURN DISTINCT a.name AS Actor, a.born AS Born
order by a.born
I modify the query using pattern comprehension below and it returns 15443 rows, but all of them are empty arrays.
MATCH (a:Actor)
with a, [ (a where a.born is not null)-[:ACTED_IN]->(m:Movie where m.year = 2000) | a.name ] as Actors
return Actors
My intent is to return a list of actors just like the first query. What went wrong in the second query?
答案1
得分: 1
这将为您提供不同的演员:
WITH [(a:Actor WHERE a.born IS NOT NULL)-[:ACTED_IN]->(m:Movie WHERE m.year = 2000)|a.name] AS actorList
UNWIND actorList AS actor
RETURN DISTINCT actor
英文:
[UPDATED]
This will give you the distinct actors:
WITH [(a:Actor WHERE a.born IS NOT NULL)-[:ACTED_IN]->(m:Movie WHERE m.year = 2000)|a.name] AS actorList
UNWIND actorList AS actor
RETURN DISTINCT actor
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论