如何计算Elixir中查询结果的总和?
我有一张如何计算Elixir中查询结果的总和?,elixir,phoenix-framework,arithmetic-expressions,Elixir,Phoenix Framework,Arithmetic Expressions,我有一张订单表格。此表的一列是总价 通过将订单项目和项目属性 当用户删除一个order\u项目时,我想让它删除所有与order\u项目相关的item\u属性。因此,在计算总价时,它应该扣除订单项目和项目属性的价格 为此,我编写了如下代码 order_item_total = Repo.one!(from p in Pos8.OrderItem, where: p.order_id == ^order_id, select: sum(p.item_total)) total_item_attrib
订单
表格。此表的一列是总价
通过将订单项目
和项目属性
当用户删除一个order\u项目
时,我想让它删除所有与order\u项目
相关的item\u属性
。因此,在计算总价时,它应该扣除订单项目
和项目属性
的价格
为此,我编写了如下代码
order_item_total = Repo.one!(from p in Pos8.OrderItem, where: p.order_id == ^order_id, select: sum(p.item_total))
total_item_attributes_price = Repo.one!(from p in Pos8.ItemAttribute, where: p.order_id == ^order_id, select: sum(p.price))
order_total_query = (order_item_total + total_item_attributes_price)
Pos8.Order.changeset(order, %{total: order_total_query})
|> Repo.insert_or_update
删除订单项目
和项目属性
后,选择与订单id
相关的订单项目
和项目属性
的总价之和。然后将其值输入订单数据库
但是,它会触发算术表达式中的(算术错误)错误参数。这表明order\u total\u query=(order\u item\u total+total\u item\u attributes\u price)
在算术表达式中不是有效参数
我应该如何用正确的算术表达式计算订单总数查询
提前感谢。如何使用 打印order\u item\u total
的值和total\u item\u attributes\u price
将对您有所帮助