简单的Cypher查询百分比计算

时间:2018-04-24 07:52:57

标签: neo4j cypher

我有很多产品,想知道有多少百分比有效, 我是Cypher的新手并试图使用WITH keyword但没有成功:

MATCH (n:ratedItem) 
WHERE n.idCategory = "45" AND 
  n.isValidate = "1" AND 
  n.value_fr = 1 
WITH count(n) as totalValidate 
MATCH (n:ratedItem) 
WHERE n.idCategory = "45" 
WITH count(n) as total 
RETURN (totalValidate / total) * 100

我有语法错误,似乎Cypher不知道第一个计数totalValidate

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

你已经忘记了第二个WITH

MATCH (n:ratedItem) 
WHERE n.idCategory = "45" AND 
  n.isValidate = "1" AND 
  n.value_fr = 1 
WITH count(n) as totalValidate 
MATCH (n:ratedItem) 
WHERE n.idCategory = "45" 
WITH count(n) as total, totalValidate
RETURN (totalValidate / total) * 100