Skip to content

Instantly share code, notes, and snippets.

@cskardon
Last active November 7, 2024 13:51
Show Gist options
  • Save cskardon/be7543a0fd5b19a07c4c421ff8eae78c to your computer and use it in GitHub Desktop.
Save cskardon/be7543a0fd5b19a07c4c421ff8eae78c to your computer and use it in GitHub Desktop.
A gist of the queries used in the Advanced Neo4j course for conditional logic
//001 - Deceased
MATCH (person:Person)
WHERE NOT person.died IS NULL
SET person:Deceased;
//002 - Alive
MATCH (person:Person)
WHERE person.died IS NULL
SET person:Alive;
//003 - Cleanup the additional labels so we can do it again
MATCH (person:Person)
REMOVE person:Alive, person:Deceased;
//004 - APOC Alive or deceased
MATCH (person:Person)
CALL apoc.do.when(
person.died IS NULL,
'SET person:Alive',
'SET person:Deceased',
{person:person}
) YIELD value
RETURN DISTINCT "done";
//005 - Cleanup the additional labels so we can do it again
MATCH (person:Person)
REMOVE person:Alive, person:Deceased;
//006 - CALL Subquery Alive or deceased
MATCH (person:Person)
CALL { WITH person
WITH person WHERE person.died IS NOT NULL
SET person:Alive
}
CALL { WITH person
WITH person WHERE person.died IS NULL
SET person:Deceased
}
RETURN count(*);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment