如何在NDB中找到每个组的最大值 [英] How to find the max value per group in NDB

查看:84
本文介绍了如何在NDB中找到每个组的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用了ndb的python。
如何在NDB中找到每个组的最大值?



我的表

  user_id | level_number |得分
-------- + -------------- + --------------------
1 | 1 | 15
1 | 1 | 5
1 | 2 | 26
1 | 2 | 30

我想每个关卡都获得最高分数

解决方案

从我所看到的情况来看,最好的做法是在score_number = 1,然后是2,然后是3的情况下对排序顺序进行查询。由于数据存储不能执行计算,如果你不想在你的代码中进行计算,你需要使用排序并保持最高的排序。



我个人有分数链接到父级实体级别,然后查询每个祖先并检查最高分数。

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.

这篇关于如何在NDB中找到每个组的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆