在单个查询中比较Cypher / Neo4J中的节点计数

时间:2015-08-15 10:31:06

标签: neo4j cypher

我正在尝试对cypher查询进行整形以选择节点数,然后计算具有特定类型链接的节点的百分比。基本上这位医生参加了多少次预约,其中有多少次导致关节炎诊断?

所以我从所有节点的计数开始

    (d:Doctor)-[ATTENDED]-(apt:Appointment)
    RETURN d.name, count(apt)

然后我想将上面的计数与满足这种模式的数字进行比较

    (d:Doctor)-[*1..2]-(c:Condition {desc:'Arthritis'})
    RETURN d.name, count(c)

我知道我很愚蠢,必须有一种简单的方法来使用UNION或WITH来调整结果,但是我的尝试导致执行时间非常长,结果错误!

我希望看到一张类似下面的表......

Dr:Zhivago博士,总数:850,关节炎:8%

由于

1 个答案:

答案 0 :(得分:1)

写这个问题有帮助!

MATCH (c:Doctor)-[*0..2]-(d:Condition {desc:'Arthritis'})
WITH c AS doctor, count(d) AS arthritis_count
MATCH (doctor)-[]-(v:Appointment)
RETURN consultant.name, arthritis_count, count(v)