Ecto:添加查询结果

发布于 2025-01-12 22:22:12 字数 360 浏览 0 评论 0原文

我是凤凰城的新手,我有一张积分表。我试图从一种积分中扣除另一种积分。

q1 = from p in Point, where: (p.i_id == ^user), select: sum(p.points)
claims = Repo.all(q1)
q2 = from c in Point, where: (c.r_id == ^user), select: sum(c.points)
points = Repo.all(q2)
balance = points - claims

但我得到了

bad arithmetic expression

如何添加或减去查询结果?

I'm new to Phoenix and I have a points table. I'm trying to deduct one kind of points from another kind of points.

q1 = from p in Point, where: (p.i_id == ^user), select: sum(p.points)
claims = Repo.all(q1)
q2 = from c in Point, where: (c.r_id == ^user), select: sum(c.points)
points = Repo.all(q2)
balance = points - claims

But I get

bad arithmetic expression

How do I add or subtract query results?

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

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

发布评论

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

评论(1

初见终念 2025-01-19 22:22:12

Repo.all 将始终返回一个列表,如下所示:[1]

请改用 Repo.one,它将返回单个值,例如 1

Repo.all will always return a list, like this: [1].

Use Repo.one instead, which will return a single value, e.g. 1.

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