'neo4j how to use where conditionally
I have the following query:
MATCH (u: User {id: '...'})-[r:EXECUTING]->(journey: Journey)
WHERE r.progress > 0 AND r.progress < 100
RETURN journey;
It loads all journeys that are attached to a user with :EXECUTING
if the relationship's progress
property is between 1 and 100.
Now I want to add a condition for the part behind the AND
--> so the WHERE
should only be r.progress > 0
(without the AND
...).
I saw that there are CASE
/WHEN
/THEN
but think that there must be a quicker solution?
Example "The where should check r.progress to be between 0 and 50 if a certain variable is false. If the variable is true, it should check r.progress to be between 0 and 100"
Thanks in advance!
Solution 1:[1]
Based on your description
Example "The where should check r.progress to be between 0 and 50 if a certain variable is false. If the variable is true, it should check r.progress to be between 0 and 100"
I'd write the following WHERE
clause:
WHERE (
(variable = FALSE AND (r.progress > 0 AND r.progress < 50 ))
OR
(variable = TRUE AND (r.progress > 0 AND r.progress < 100 ))
)
But not sure it is "quicker" than a CASE/WHEN.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | stellasia |