Issue
I am using Jupyter Notebook to run cypher queries via py2neo and pygds libraries. I can run the cypher queries via neo4j browser too.
This command gives me the counts:
gds.run_cypher('MATCH u=(p:Nodelabel1 {property1: "Nodelabel2"})-[r:relationship1]->WHERE r.integer > 10 RETURN Count (u)')
Output is:
| | Count (u) |
|0 | 526 |
I want to set these counts as 1's and the ones which are not in this count as 0's i:e which are r.integer < 10, under Nodelabel1 with a new variable/property name ofcourse.
I tried it using the two rows method Nathan Smith has shown below. I got the counts for the two categories too. But when I try
gds.run_cypher('MATCH(u:Nodelabel1) RETURN u.category AS category, count(u) AS cnt')
I get:
| | category | cnt
|0 | None | 120711
I expect to get:
| | category | cnt
|0 | Less than or equal to 10 | 20733
|1 | Greater than 10 | 526
Solution
If you want the answer in two rows, do it this way:
gds.run_cypher("""
MATCH (p:Nodelabel1 {property1: "Nodelabel2"})-[r:relationship1]->()
RETURN
CASE WHEN r.integer > 10 THEN "Greater than 10"
ELSE "Less than or equal to 10" END AS category,
Count (*) AS count
""")
If you want the answer in two columns, do it this way:
gds.run_cypher("""
MATCH (p:Nodelabel1 {property1: "Nodelabel2"})-[r:relationship1]->()
WITH
SUM(CASE WHEN r.integer > 10 THEN 1
ELSE 0 END) AS greaterThanTen,
Count (*) AS total
RETURN greaterThanTen, total - greaterThanTen AS lessThanOrEqualToTen
""")
Answered By - Nathan Smith
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.