使用模式推导修改后的密码查询没有返回任何行。

huangapple go评论56阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年2月7日 02:59:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75365499.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定