Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-21-2020 06:58 AM
Hi, I have setup following relationship
Customer - [Buys] -> Stocks
I am pulling most popular stock as
MATCH (n:Customer)-[:BUYS]->(s:Stock) RETURN s,count(distinct n) as cnt order by cnt desc limit 1
Buy
relation have Quantity, unit price and invoice date
properties.
I need to find 2 things.
Any guidance on this shall be very helpful.
12-21-2020 08:01 AM
It might make sense to model the transaction as it's own node for more involved querying/operations.
WHERE abs(popularBuy.timestamp - buy.timestamp) < X
or
WHERE popularBuy.timestamp - duration('3D') < buy.timestamp < popularBuy.timestamp + duration('3D')
compute the delta between last and first month as duration
starting from first month add a duration of +1 for each month
create a boolean list with true, false for each month and then a reduce that computes the running totals
reduce(result=[0,0], x in bought | case when x then [result[0], result[1]+1] else case result[1] > result[0] then [result[1],0] else [result[0],0] end)
and then result[0] has your highest consecutive
you can of course also combine that into one operation
alternatively compute the "has bought previous month" and aggregate them e.g. on the min or max month of consecutive purchases
01-11-2021 08:12 AM
Hi,
Are you able to find the solution for these queries?
Kindly share.
Thanks,
Ankit Gupta
All the sessions of the conference are now available online