gpt4 book ai didi

neo4j - return 语句中两组之间的差异

转载 作者:行者123 更新时间:2023-12-04 00:30:25 27 4
gpt4 key购买 nike

我有一个架构,如:主题有帖子,用户写主题和帖子。我想找到推荐的主题。在我的示例中,我返回 count(topics) 和 count(rec_topics)。怎么可能返回这些集合之间的差异?赞 [1,2] - [1] = [2]谢谢

MATCH (user:User {first_name: 'Hlavní' }),
user<-[:wrote_by]-(posts:Post)<-[:TOPIC]-(topics:Topic)-[:TOPIC]->(all_posts:Post)-[:wrote_by]->(friends:User)<-[:wrote_by]-(friends_posts:Post)<-[:TOPIC]-(rec_topics:Topic)
WHERE NOT(topics=rec_topics)
RETURN count(DISTINCT topics),count(DISTINCT rec_topics);

最佳答案

您可以使用 collect为主题和 rec_topics 建立一个集合。在第二步中,列表推导可用于仅返回那些不属于 rec_topics 的主题:

MATCH (user:User {first_name: 'Hlavní' }),
user<-[:wrote_by]-(posts:Post)<-[:TOPIC]-(topics:Topic)-[:TOPIC]->
(all_posts:Post)-[:wrote_by]->(friends:User)<-[:wrote_by]-
(friends_posts:Post)<-[:TOPIC]-(rec_topics:Topic)
WHERE NOT(topics=rec_topics)
WITH collect(DISTINCT topics) as topics, collect(distinct rec_topics) as rec_topics
RETURN [x in topics WHERE not(x in rec_topics)] as delta,
length(topics), length(rec_topics)

关于neo4j - return 语句中两组之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28894098/

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