neo4j 我想得到每个用户帖子的总React数的总和,下面我分别得到了所有React的计数如何得到每个用户的总计数

mjqavswn  于 2022-11-05  发布在  React
关注(0)|答案(1)|浏览(142)

我想在另一列中分别得到所有React的总数。下面我得到了所有用户得到的每个React的计数。我想输出有另一列,其中显示Michael -- totalReations = 4

我试着得到每种React类型的计数,现在我想要一个单独的所有React的计数,我想要所有以前的元素,因为它是。谢谢你这么多的时间和帮助。

MATCH (z:User )-[re:REACTED] -> (p:Post)<-[:POSTED]-(x:User) 
WHERE exists(re.type) 
RETURN x.name as postOwner, re.type as rectionType, count(re) as noOfReactions, collect(re.type);
xqkwcwgp

xqkwcwgp1#

试试看:

MATCH (z:User )-[re:REACTED]->(p:Post)<-[:POSTED]-(x:User) 
WHERE exists(re.type) 
WITH x.name as postOwner, collect(re.type) AS reactions
WITH postOwner, size(reactions) AS totalReactions, reactions, reactions AS reactionsCopy
UNWIND reactionsCopy AS reactionType
WITH postOwner, totalReactions, reactionType, [x IN reactions WHERE x = reactionType | x] AS listOfMatchingReactions
RETURN postOwner, totalReactions, reactionType, size(listOfMatchingReactions) AS noOfReactions, listOfMatchingReactions

在这里,我们首先收集一个列表中的所有React,然后计算它的大小,得到React的总数,然后展开列表的副本,计算每种不同类型的React的计数。

相关问题