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

在单个查询中比较Cypher/Neo4J中的节点计数,neo4j,cypher,Neo4j,Cypher,我正在尝试构造一个密码查询,以选择节点数,然后计算具有特定类型链接的节点的百分比。基本上,这位医生参加了多少次预约,其中有多少次被诊断为关节炎 所以我从所有节点的计数开始 (d:Doctor)-[ATTENDED]-(apt:Appointment) RETURN d.name, count(apt) 然后我想将上述计数与满足此模式的数字进行比较 (d:Doctor)-[*1..2]-(c:Condition {desc:'Arthritis'}) RETURN

我正在尝试构造一个密码查询,以选择节点数,然后计算具有特定类型链接的节点的百分比。基本上,这位医生参加了多少次预约,其中有多少次被诊断为关节炎

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

    (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来塑造结果,但我的尝试导致执行时间过长,结果错误

我想看一张像下面这样的桌子

医生:日瓦戈医生,总数:850,关节炎:8%


谢谢你写的问题对我有帮助

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)

我会试着找出模型

match 
(c:Doctor)-[ATTENDED]->(apt:Appointment),
(apt)-[*0..1]->(d:Condition {desc:'Arthritis'}) 
with c as consultant, count(c) as appointments, count(d) as arthritis
return consultant.name as name, appointments as total, arthritis/appointments * 100 as arthritis 

希望能有所帮助。

您可以发布模型吗?否则可能会有点难以帮助。