对象盒,通过分组另一个属性来总和一个属性

发布于 2025-02-04 02:32:56 字数 617 浏览 4 评论 0原文

想象一下,我有一个表:

tagid数量
1100
1150
2200
2250

,我需要通过对tagid进行分组来概括金额

在SQL中,我们可以通过: 选择tagid,tagid的订单组中的sum(量);

查询结果:

tagidsum(量)
1250
2450

我如何在对象盒中获得此类结果?

Imagine I have this table:

tagIdamount
1100
1150
2200
2250

And i need to sum the amount by grouping the tagId.

In SQL we can do this by:
SELECT tagId, SUM(amount) FROM orders GROUP BY tagId;

Query result:

tagIdSUM(amount)
1250
2450

How can I get such results in ObjectBox ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆光下的微笑 2025-02-11 02:32:56

Object Box中没有组函数。取而代之的是,编写代码以处理您想要的任何方式。有内置的属性查询可以返回可能有用的总和:

val sum = tagBox.query(Tag_.id.equals(id)).build()
    .property(Tag_.amount)
    .sumDouble()

源: https:// docs https:// docs .objectbox.io/queries#propertyquery

There is no GROUP function in ObjectBox. Instead, write code to process query results in which ever way you desire. There are built-in property queries that can return a sum that may be helpful:

val sum = tagBox.query(Tag_.id.equals(id)).build()
    .property(Tag_.amount)
    .sumDouble()

Source: https://docs.objectbox.io/queries#propertyquery

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文