cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Find maximum possible value property could be. <MATCH (n:Node) WHERE not n.property='unknown' RETURN max(n.property)> not working as expected

I'm trying to find the maximum possible value a property can have excluding one property.
In generic syntax:

MATCH (n:Node) WHERE not n.property='unknown' 
RETURN max(n.property)

I tried the cypher query:

MATCH (f:FlavinAtom) WHERE not f.SASA_atom='unknown'
RETURN max(f.SASA_atom)

Which returns "9.99.." but I know, based on the CSV value that I imported it should be "52.54..." Also, I can find the node I'm looking for and the value I expect when I look it up by it's ID, see screenshot:

Also, I can find the value in the list when I use the following cypher query and export to CSV:

MATCH (p:FlavinAtom) WHERE exists(p.SASA_atom)
RETURN p.AtomID, id(p), p.SASA_atom ORDER BY p.SASA_atom DESC LIMIT 5000

Why doesn't the simple query below return the expected result?

MATCH (f:FlavinAtom) WHERE not f.SASA_atom='unknown'
RETURN max(f.SASA_atom)

Thanks!

1 ACCEPTED SOLUTION

MATCH (f:FlavinAtom) WHERE not f.SASA_atom='unknown'
SET f.SASA_atom = toFloat(f.SASA_atom)
RETURN max(f.SASA_atom)

It works, thank you!

View solution in original post

3 REPLIES 3

Update:

These versions of the query:

MATCH (f:FlavinAtom) WHERE not f.SASA_atom='unknown'
WITH max(f.SASA_atom) as highestSASA 
MATCH (f2:FlavinAtom) 
where f2.SASA_atom = highestSASA
return f2;
MATCH (f:FlavinAtom) WHERE not f.SASA_atom='unknown'
RETURN f 
ORDER BY f.SASA_atom DESC
LIMIT 1

Which I found here: Find node with maximal (minimal) values of property in Neo4j - Stack Overflow
Also don't work.

Hello @emroberts95

I think there is a problem of type, you should make sure all your nodes with a float property are floats.

Regards,
Cobra

MATCH (f:FlavinAtom) WHERE not f.SASA_atom='unknown'
SET f.SASA_atom = toFloat(f.SASA_atom)
RETURN max(f.SASA_atom)

It works, thank you!