Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-19-2020 07:47 AM
Hi,
is there a chance to use MIN, MAX in Cypher like in the following example, or is it possible to save the rand()- value into a variable and use the variable in the same cypher- statement.
MATCH (:Person)-[c:Meeting]->(q:Person)
WHERE (q.att1 = 0) AND
( rand() < MIN( 0.25, MAX( 0.01, 1 / MAX( 1, c.distance/1000.0))))
SET q.att2 = 1
You see, I'm a beginner. Thanks for your help.
Reinhold
05-19-2020 07:54 AM
Hello:)
WITH rand() AS r
MATCH (:Person)-[c:Meeting]->(q:Person)
WHERE (q.att1 = 0)
AND (r < MIN( 0.25, MAX( 0.01, 1 / MAX( 1, c.distance/1000.0))))
SET q.att2 = 1
05-19-2020 08:00 AM
Thank you very much!
Reinhold
05-19-2020 08:05 AM
No problem, a pleasure:)
05-19-2020 08:12 AM
Hi,
sorry for another question. I suppose, the statement above produces only one random value for each query. Is this correct? But I need a random value for each selected record. Does following query works?
MATCH (:Person)-[c:Meeting]->(q:Person)
WHERE (q.att1 = 0)
AND (rand() < MIN( 0.25, MAX( 0.01, 1 / MAX( 1, c.distance/1000.0))))
SET q.att2 = 1
I didn't know that MIN/MAX statements works in Cypher.
And sorry for my English.
Reinhold
05-19-2020 08:15 AM
Yes, you right, but if you still want to keep the rand value to use it later in the query, try this:
MATCH (:Person)-[c:Meeting]->(q:Person)
WHERE q.att1 = 0
WITH q, c.distance AS dist, rand() AS r
WHERE (r < MIN( 0.25, MAX( 0.01, 1 / MAX( 1, dist/1000.0))))
SET q.att2 = 1
All the sessions of the conference are now available online