Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Last active May 9, 2019 16:00
Show Gist options
  • Save vladbatushkov/1d344a102e745918466b076354eca0c1 to your computer and use it in GitHub Desktop.
Save vladbatushkov/1d344a102e745918466b076354eca0c1 to your computer and use it in GitHub Desktop.
List ordered by year with number of joined countries + total + enumeration of countries.
MATCH (c:Country)-[:JOINED_AT]->(y:Year)
WITH y.value as year, apoc.coll.sort(collect(c.name)) as cs
WITH year, reduce(r = "", x IN cs | CASE WHEN r = "" THEN x ELSE (r + ", " + x) END) as desc, reduce(n = 0, x IN cs | n + 1) as num
WITH collect({ year: year, num: num, desc: desc }) as all
WITH all, reduce(s = 0, x IN all | s + x.num) as total
WITH apoc.coll.union(all, [{ year: "Total", num: total, desc: "" }]) as result
UNWIND result as item
RETURN item.year as year, item.num as countriesJoined, item.desc as countries
ORDER BY item.year
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment