Brij Raj Singh - MSFT
Brij Raj Singh - MSFT

Reputation: 5113

Begin in cypher - get Actors acted in past 2 years

how do i found actors that acted only in a certain year/s and not before that

i tried writing a query, but that limits me to finding actors that acted in a certain year but doesn't restrain at finding the actors acting in past years.

MATCH (actor:Actor)-[:ACTS_IN]->(actorMovies) where actorMovies.year = 2014
 RETURN actor.name Limit 100

Basically I would like to find an actor who acted in movies in 2014 only and another set of actors who acted in 90's decade only.

Upvotes: 1

Views: 64

Answers (2)

Mark Needham
Mark Needham

Reputation: 2128

Basically I would like to find an actor who acted in movies in 2014 only and another set of actors who acted in 90's decade only.

One way you could do this is to write two queries and join them together with a union:

MATCH (actor:Actor)-[:ACTS_IN]->(actorMovies) where actorMovies.year = 2014
RETURN actor.name

UNION

MATCH (actor:Actor)-[:ACTS_IN]->(actorMovies) where actorMovies.year >= 1990 AND actorMovies.year < 2000
RETURN actor.name

Upvotes: 2

nawroth
nawroth

Reputation: 4361

Using the data in this example: http://neo4j.com/docs/stable/cypherdoc-movie-database.html you can do things like:

MATCH (actor:Actor)-[:ACTS_IN]->(actorMovies)
WITH actor, collect(actorMovies.year) AS years
WHERE '1999-03-31' IN years
RETURN actor.name

The point is to do the aggregation in the WITH clause, and then use the result in a WHERE clause afterwards.

If integers are used for the years, the WHERE clause could look like this:

WHERE 1999 IN years

Upvotes: 1

Related Questions