0

Take for example the following scenario:

A hospital node is related to many doctor nodes. Doctor nodes are related to other doctors representing when they refer a patient to another doctor. These referrals can be to a doctor at a different hospital. The relationship between doctors has a property called count that indicates how many times that doctor has referred any of their patients to that second doctor.

What I'm trying to do is take these referral relationships and look at it from the hospital level. My query currently looks like this:

START hospital1 = Node:Hospitals("*:*")
MATCH (hospital1)-[:CHILD_DOCTOR]->(doctor1)-[referral:REFERRED]-(doctor2)<-[:CHILD_DOCTOR]-(hospital2)
WHERE hospital1 <> hospital2
RETURN DISTINCT hospital1, hospital2, referral.count

It sounds complicated but the query is pretty straight forward. Here's the only problem. Let's say two doctors from Hospital A refer a patient to two doctors from Hospital B, I'll end up with two records where hospital1 = Hospital A, and hospital2 = Hospital B. I want to combine these results together and add the referral.count properties together. Is there any way to do this with Cypher?

4

1 回答 1

3

不确定我是否正确理解了您的域。我的理解是,您在两家任意医院之间有很多路径(也称为转诊),并且想要总结它们。在这种情况下使用

START hospital1 = Node:Hospitals("*:*")
MATCH (hospital1)-[:CHILD_DOCTOR]->(doctor1)-[referral:REFERRED]-(doctor2)<-[:CHILD_DOCTOR]-(hospital2)
WHERE hospital1 <> hospital2
RETURN hospital1, hospital2, sum(referral.count)

NB 自己没有尝试查询。如需进一步讨论,请在http://console.neo4j.org上创建一个示例数据集。

于 2013-10-11T21:03:37.080 回答