Total Pageviews

2018/10/15

[Neo4j] How to implement having clause in cypher?

假設我透過以下 Cypher 語法,查詢到在某時間區間內,每個醫生、開立某種藥物以及次數
match (doc:Doctor)-[r1:PRESCRIBES]->(med:Medicine)
where r1.date >= "20180401" and r1.date <= "20180415"     
with doc.name as doctor, med.name as medicine, count(med.name) as prescription_frequency
return doctor, medicine, prescription_frequency
order by prescription_frequency desc



如果我想要撈出 prescription_frequency >= 3 的資料,語法修正如下:
match (doc:Doctor)-[r1:PRESCRIBES]->(med:Medicine)
where r1.date >= "20180401" and r1.date <= "20180415"     
with doc.name as doctor, med.name as medicine, count(med.name) as prescription_frequency 
where prescription_frequency >= 3
return doctor, medicine, prescription_frequency
order by prescription_frequency desc







No comments: