I'm used python with ndb in my app. How to find the max value per group in NDB?
My table
user_id | level_number | score
--------+--------------+--------------------
1 | 1 | 15
1 | 1 | 5
1 | 2 | 26
1 | 2 | 30
I want to get max score each level
From what I can see, the best would be to do a query with a sort order on the score where level_number = 1, then 2, then 3. Since the datastore cannot do computations, you'll need to use the sorting and just keep the highest one, if you don't want to do computations in your code.
I would personally have the scores linked to a parent entity "level", and then query per ancestor and check the highest score.