Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-13-2021 01:40 AM
Suppose I collect two list from last query L1 and L2, L1 is [8, 9, 5, 3] and L2 is [4, 7, 1] and I wish to get the one step bigger item in L1 comparing with L2, so the expected output is [5, 8, 3]. How could cypher do this?
07-13-2021 02:33 AM
Got half of the answer, when I query with following, it shows
with [4, 7, 1] as L2, [8, 9, 5, 3] as L1
unwind L2 as l2
with [x in L1 where x > l2] as cl
return cl
That's the half way and what I need to do is only to take the minimum value of from each list and got the final result, therefore I add a min() function
with [4, 7, 1] as L2, [8, 9, 5, 3] as L1
unwind L2 as l2
with [x in L1 where x > l2] as cl
return min(cl)
it returns
It seems that it returns me the min value in the wrong dim
07-13-2021 07:17 AM
Hey @oli ,
You can try apoc.coll.sort()
function to solve this problem. I have written the code as well you can run it and test it.
with [4, 7, 1] as L2, [8, 9, 5, 3] as L1
unwind L2 as l2
with [x in L1 where x > l2] as cl
with apoc.coll.sort(cl) as cl
with collect(cl[0]) as cl
return cl
Thanks,
Rishabh
07-13-2021 06:14 PM
Thanks prishabh for your answer, do you know how could I set the order of asc or desc?
07-16-2021 05:15 AM
@oli you can use the ORDER BY x.abc ASC or DESC. But in your scenario, it is creating a list of list s it is sorting only the list not values inside the list.
07-18-2021 05:25 PM
Yeah, I know. since apoc.coll.sort() just sort the value in asc order, that's why I would to ask how to sort the list in desc order. For the second question, I got the answer already, it's about how to unwind and save the value locally instead of globally.
07-13-2021 06:24 PM
besides, can I use unwind and make the value used in the where condition?
07-16-2021 05:16 AM
I couldn't understood your second question. Could you please create a example and ask?
05-26-2022 07:38 AM
Hi,
Just chiming in because this answer was super helpful to me. I'm facing a very similar problem right now and couldn't find a solution off the top of my head.
Thank you and the community!
07-20-2021 07:16 AM
@oli I couldn't find a way to sort in descending order. But, you can check an apoc.iterate function.
All the sessions of the conference are now available online