使用计数从 GAE 数据存储查询
目前,我从数据存储中获得 Android 应用程序的最高分,如下所示:
Query query = pm.newQuery(PlayerPersistentData.class);
query.setOrdering("rating desc");
query.setRange(0, 25);
但是,我还想按辅助列的计数对结果进行排序:
例如,在普通 SQL 中,它会是这样的:
select PlayerPersistentData.*, count(achievements) as achievements_count
from PlayerPersistentData
order by rating desc, achievements_count desc
成就是在数据存储中定义如下
@Persistent
private Set<Integer> achievements;
这可以使用 GAE 数据存储吗?如果是这样,我应该如何创建我的查询?
提前致谢
At the moment I am getting the top scores for my Android application from the datastore as follows:
Query query = pm.newQuery(PlayerPersistentData.class);
query.setOrdering("rating desc");
query.setRange(0, 25);
However, I would also like to order the results by the count of a secondary column:
E.g. In normal SQL it would be something like this:
select PlayerPersistentData.*, count(achievements) as achievements_count
from PlayerPersistentData
order by rating desc, achievements_count desc
Achievements is defined in the datastore as follows
@Persistent
private Set<Integer> achievements;
Is this possible using the GAE datastore? And if so how should I create my query?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 addSort 方法到您的 Query 对象,如下所示:
You can use the method addSort to your Query object like this:
您需要非规范化:将计数存储为实体上的单独字段,然后对其进行查询。
You need to denormalize: store the count as a separate field on your entity, and query on that.