Neo4j:比较关系属性是数组类型

时间:2017-12-11 10:50:15

标签: arrays neo4j cypher graph-databases

我想列出利物浦输掉比赛的数量。

我的代码:

match(a:Club{name:'Liverpool FC'})-[r:played_with]->(b:Club)
WHERE r.score[0]<r.score[1] return count(r) as result
UNION
match(a:Club)-[r:played_with]->(b:Club{name:'Liverpool FC'})
WHERE r.score[0]>r.score[1] return count(r) as result

我期待一个结果,但它显示两个。

Data model

2 个答案:

答案 0 :(得分:2)

[增订]

如果你想看看利物浦队失利多少次,你可以使用非定向关系模式:

MATCH (a:Club{name:'Liverpool FC'})-[r:played_with]-(:Club)
WHERE CASE WHEN a = STARTNODE(r)
  THEN r.score[0]<r.score[1]
  ELSE r.score[1]<r.score[0] END
RETURN COUNT(r) as result;

答案 1 :(得分:0)

我认为您不需要UNION来完成这项工作。试试这个:

MATCH (a:Club{name:'Liverpool FC'})
OPTIONAL MATCH (a)-[r:played_with]->(:Club)
WHERE r.score[0]<r.score[1] 
WITH a, count(r) as result1
OPTIONAL MATCH (a)<-[r:played_with]-()
WHERE r.score[0]>r.score[1] 
WITH a, result1, count(r) as result2
RETURN result1 + result2