Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-04-2020 06:36 PM
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.
Solved! Go to Solution.
08-05-2020 01:15 AM
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
08-05-2020 01:15 AM
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
08-05-2020 10:24 AM
Hi Koji
Thanks, that solved the problem, now are computing correctly.
All the sessions of the conference are now available online