Compute highest and lowest occurrence of relationship between two nodes by relationship property

In my example i have the following association:

(a1:Author)-[co:COAUTHOR]->(a2:Author)

Which every COAUTHOR relationship has a year property.

I tried to compute the highest and lowest occurrence of co authorship relationship between authors, from distinct a1:Author by year with Cypher using the WHERE clause, with an array of years. When testing only one value in array of years, i get the right values, but with more years in array, the counting of minAmount and maxAmount are accumulating all years i put in array, then things become wrong.

The following code i tried:

MATCH (a1:Author)-[co:COAUTHOR]-(a2:Author) WHERE co.year IN [2018] // problem here if put more years

WITH a1,count (co) as amount

WITH MIN(amount) as minAmount, MAX(amount) as maxAmount

return  minAmount,maxAmount

I tried to use FOREACH , CASE and others to loop over years in array of years and compute the highest and lowest ocurrence by year separated, but without success.

Hi,

How about this one.
I just added "co.year AS year" at first WITH clause.

MATCH (a1:Author)-[co:COAUTHOR]-(a2:Author)
  WHERE co.year IN [2017, 2018] // problem here if put more years
WITH co.year AS year, a1, count(co) AS amount
WITH min(amount) AS minAmount, max(amount) AS maxAmount
RETURN minAmount, maxAmount
1 Like

Hi Koji

Thanks, that solved the problem, now are computing correctly.

1 Like