Limit results per year in movies example

How should I write this so it only returns at most 20 actors of the top 3 revenue movies in each year?

  MATCH (a:Actor:Actor)-[r:ACTED_IN]->(m:Movie) 
  WHERE (m.year<1980) 
  RETURN a{id: id(a), labels: labels(a), .name }, m{id: id(a), .title}

I would think this would give me 3 rows :slight_smile:

MATCH (p:Person)-[:ACTED_IN]->(m:Movie{title:'Mummy, The'})
CALL {
    WITH p
    MATCH (p)
    RETURN p as lp
    LIMIT 3
}
RETURN lp.name, m.title


MATCH (m:Movie{title:'Mummy, The'})
WHERE m.year=1999 // there are more
CALL {
    WITH m
    MATCH (p:Person)-[:ACTED_IN]->(m)
    RETURN p as lp
    LIMIT 3
}
RETURN lp.name, m.title

Courtesy of chatgpt, crazy ...

MATCH (m:Movie)
WHERE m.revenue IS NOT NULL AND m.year IS NOT NULL
WITH m.year AS year, m
ORDER BY year, m.revenue DESC
WITH year, collect(m)[..2] AS tm
UNWIND tm AS hm
MATCH (hm)<-[r:ACTED_IN]-(a:Person)
RETURN year, a.name as nodes, r.role as links, hm.title as nodes2
ORDER BY year