Created
April 20, 2023 12:29
-
-
Save adam-cowley/789abe70b4352f4622fc7e67413ce2a5 to your computer and use it in GitHub Desktop.
Next-level Cypher aggregations using WITH, COLLECT and UNWIND!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MATCH (u:User)-[:HAS_ENROLMENT]->(e:CompletedEnrolment) | |
WHERE e.completedAt >= datetime('2021-01-01') | |
WITH | |
e.completedAt.year +'-'+ e.completedAt.quarter AS quarter, | |
count(*) AS count | |
WITH collect({quarter: quarter, count: count}) AS all | |
UNWIND range(0, size(all)-1) AS idx | |
RETURN idx, | |
all[idx].quarter AS quarter, | |
all[idx].count AS count, | |
CASE WHEN idx > 0 THEN apoc.math.round((100.0 * all[idx].count / all[idx+1].count), 2) ELSE null END AS change | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment