gpt4 book ai didi

Neo4j:如何更好地编写此查询?

转载 作者:行者123 更新时间:2023-12-01 00:26:19 25 4
gpt4 key购买 nike

我是 Neo4j 的新手。我试图做这个查询:

"Mati Gol would like to watch a new movie. therefore would like to get the following list of movies: Write a query that returns all movies that were LIKED by any person who is a FRIEND of the person with the name Mati Gol or is a FRIEND of a FRIEND of Mati Gol, excluding all movies WATCHED by Mati Gol."



我的查询是:
MATCH (a:person {name:"Moti Gol"})-[:WATCHED]->(b)
WITH collect(b) AS Already_Watched
MATCH (a:person {name:"Moti Gol"})-[:FRIEND*1..2]->(b)-[:LIKED]->(c)
WITH collect(c) AS Friend_Liked
(movie:Friend_Liked) WHERE NOT (movie.name) IN Already_Watched
RETURN movie.name

这个查询好吗?有人可以为我提供更好的写作吗?

最佳答案

您的查询有一些错误...首先,第一行没有 MATCH 语句。您正在匹配 (a:person {name:"Moti Gol"})两次并重新声明 a多变的。

执行相同查询的更简单直观的方法:

// get all the movies liked by friends or friends of friends of "Moti Gol"...
MATCH (a:person {name:"Moti Gol"})-[:FRIEND*1..2]->(b:person)-[:LIKED]->(c:movie)
// excluding all movies WATCHED by Mati Gol
WHERE NOT (a)-[:WATCHED]->(c)
// return the movies
RETURN c.name

关于Neo4j:如何更好地编写此查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44639224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com