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!

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 :slight_smile:

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

Regards,
Cobra

1 Like
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!