How to calculate and display author with most number of years publication

Here's my query and below that is returned data

MATCH (n:citations)-[:WROTE_BY]->(a:authors) with n,a,count(a.name) as c where a.name IS NOT NULL RETURN a.name,n.year order by a.name;

| "Victor Mitrana" | 1993 |
| "Victor Mitrana" | 1996 |
| "Victor Mitrana" | 1998

I need to calculate 1998-1993 , bascially max(year) - min ( year ) for each author and display author and longest publication year for each author. Not sure how to achieve it.

Hello,

This query does the trick (note : I tried on the movie database, just replace Person and Movie by Author and citation as you need)

MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WITH p, max(m.released) as max, min(m.released) as min
RETURN p, max-min+1 as yearsActive
ORDER BY p.name

Cheers !

Marius

2 Likes

Thank you so much that trick certainly worked. Now I can see author with longest career.

MATCH (p:citations)-[:WROTE_BY]->(a:authors)
WITH a, max(p.year) as max, min(p.year) as min
RETURN a.name, max-min+1 as yearsActive
ORDER BY yearsActive

1 Like