0

I have the following code:

MATCH (c1:City),(c2:City)
WHERE c1.name= 'London' AND c2.name = 'Luton'
CREATE (c2)<-[:LIVING_IN {date_of_start: 2019}]-(p:Person {name: 'Mark'});

MATCH (c1:City),(p:Person)
WHERE c1.name= 'Luton' AND p.name = 'Mark'
CREATE (p)-[:WORKING_IN {date_of_start: 2019, date_of_end: 2021}]->(c1);

MATCH (c1:City),(p:Person)
WHERE c1.name= 'London' AND p.name = 'Mark'
CREATE (p)-[:WORKING_IN {date_of_start: 2022}]->(c1);

The code defines that person has started living in a cerain city in certain year. That same person has changed the city where the work is done.

For one node I have the end date (date_of_end: 2021}), but another I don't since the work is still going on.

How can I calculate the years on the job at the latest location if I don't have year as node property?

1 Answers1

2

Is this what you look for:

MATCH (p:Person)-[e:WORKING_IN]->(c:City)
WHERE p.name = 'Mark'
RETURN p.name, c.name, coalesce(e.date_of_end, date().year) - e.date_of_start as years;
Toni
  • 390
  • 3
  • 13