2015-08-15 55 views
2

我在嘗試構造一個密碼查詢來選擇節點計數,然後計算具有特定類型鏈接的那些節點的百分比。本質上這位醫生參加了多少次約會,其中有多少人導致了關節炎診斷?在單個查詢中比較Cypher/Neo4J中的節點數

於是我開始與所有

(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%

感謝

+0

你可以張貼模型嗎?否則可能有點難以幫助。 – alacambra

回答

1

我會試圖找出模型。

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 

希望有所幫助。

+0

謝謝,它與浮標(關節炎...) – jobbietronic

+0

好點。我總是忘記百分比的浮點數:S – alacambra

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)