Reputation: 1335
I'm using Neo4j 3.0.6 and I want to do something like that :
for k in keys(r):
if k >= `2015-01`:
sum(values(k)) as sum
I tried foreach but it doesn't work. In the model, the key of my relationship is a pair of date and a criterion. Here is an example:
<id>... 2015-01,c:500 2015-02,c:23 2015-03,c:900 2015-01,r:56
The expected resulat :
sum
923
So, I'm looking to get the sum of the criterion c when it's greater than 2015-01
Thank you
Upvotes: 0
Views: 1119
Reputation: 2507
MATCH (origin:AirportFR)
WHERE origin.code IN ['JFK', 'ATX']
MATCH (destination:AirportFR)
WHERE destination.code IN ['BUY', 'PUQ']
MATCH (origin) - [r] - (destination)
UNWIND [k IN KEYS(r) WHERE split(k, ',')[0] >= '2015-01' AND split(k, ',')[1] = 'c'| r[k] ] AS c_values
RETURN SUM(c_values)
SUM
is an aggregation function that expects to collect data from several rows, so you have to get the property you want into rows. To generate these rows, you're going to have to UNWIND
a filtered list of the keys for each row. But as mentioned below, seriously consider changing your data model so that you don't have to run string analysis on your keys.
Upvotes: 1