Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何计算Elixir中查询结果的总和?_Elixir_Phoenix Framework_Arithmetic Expressions - Fatal编程技术网

如何计算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
将对您有所帮助