Finding the maximum value in a column using GQL
-
28-09-2019 - |
Question
How do I find the maximum value in a particular column of a table in the GAE datastore using GQL?
Solution
To get the max you using GQL, you could do this:
max_x = db.GqlQuery("SELECT * FROM MyModel ORDER BY x DESC").get().x
You could use this syntactically shorter but equivalent approach:
max_x = MyModel.all().order('-x').get().x
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow