Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-29-2019 08:03 PM
So I have data model that looks like this:
(u1:User)-[:create]->(trx:transfer)-[:to]->(u2:User)
and in node transfer, I have a transaction date and amount transferred as attributes. So, I'm wondering whether neo4j can give me multiple subgraphs where the total amount exceeds $500 within any one week in between 2 dates (March 1 - March 30, 2019), and only show top 5 with the highest amount?
So my concern was more on doing multiple aggregations with different starting dates. Hopefully, the question is clear enough, but please let me know if it is not.
05-13-2019 07:22 AM
Hi Darius,
Do do you have a bit more background, how many User nodes and Transfer nodes are there?
And do you mean total amount per week bigger than $500?
I would do something like this (within the same year) and an index on Transfer.date:
WITH date('2019-03-01') as fromDate
, date('2019-03-30') as toDate
, 500 as minAmount
WITH fromDate, toDate, duration.between(fromDate, toDate).weeks as numberOfWeeks
MATCH (trx:Transfer)
WHERE trx.date >= fromDate
AND trx.date <= toDate
WITH trx, numberOfWeeks
MATCH (u1:User)-[:create]->(trx)-[:to]->(u2:User)
WITH u1, u2, trx.date.week as week, sum(trx.amount) as weekTotal, collect(trx) as tts
WHERE weekTotal > minAmount
// ensure that all the weeks are above 500
WITH u1,u2, collect( {week: week, weekTotal: weekTotal, tx: tts}) as data where size(data) = numberOfWeeks
UNWIND data as dd
WITH u1,u2, dd.week as week, dd.weekTotal as weekTotal, dd.tx as trfs order by weekTotal desc limit 5
UNWIND trfs as tx
MATCH p=(u1)-[:create]->(tx)-[:to]->(u2)
RETURN p, weekTotal
some remarks:
I hope you've got some ideas...
Regards
Kees
All the sessions of the conference are now available online