比较不同条件的总和和 - 联合处理后?

时间:2018-06-09 07:23:21

标签: neo4j

嗨,我有一段关系艺术家 - 合作 - >作家,想找到谁主要写自己的歌曲的艺术家。因此,具有相同名称的作家和艺术家之间的加权边缘应该大于所有其他权重的总和。

我设法做到了:

MATCH (n:Artist)-[r:Collaborated]-(m:Writer)
WITH n, m, sum(r.weight) as wrote
WHERE n.name = toLower(m.name) 
RETURN n.name as Node, wrote ORDER BY wrote descending;

但我不确定如何纳入第二个条件。我是否必须使用联盟后处理?有任何帮助吗?

要加入两个WHERE条件,我尝试了这样的事情,并将第一笔金额与第二笔金额进行比较,但它不起作用:

MATCH (o:Artist)-[q:Collaborated]-(p:Writer)
WITH o, p, sum(q.weight) as wrote1
WHERE o.name <> toLower(p.name) 
MATCH (n:Artist)-[r:Collaborated]-(m:Writer)
WITH n, m, sum(r.weight) as wrote2
WHERE n.name = toLower(m.name)  and wrote2>wrote1
RETURN n.name as Node, wrote2;

这是我的图表的示例:

enter image description here

我想知道eminem和eminem之间的重量是否大于所有其他重量

1 个答案:

答案 0 :(得分:0)

首先,您的模型有点奇怪,您有两个节点Eminem,一个标签为Artist,另一个标签为Writer。 对于我的POV,您应该只有一个带有两个标签的节点Eminem

要回答您的问题,我认为此查询可以帮助您:

MATCH (o:Artist)-[r:Collaborated]->(p:Writer)
WITH o, CASE WHEN o.name = p.name THEN r.weight ELSE -1*r.weight END AS score
RETURN o, sum(score) AS score

如果分数高于0,那么您就知道eminem and eminem is bigger than all the other weights