Ecto:添加查询结果
我是凤凰城的新手,我有一张积分表。我试图从一种积分中扣除另一种积分。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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
.