如何使用 ecto 计算 2 列值

How to calculate 2 columns values with ecto

我想用 ecto 计算 2 列值,如下所示 SQL

SELECT goal, assist, (goal + assist) as point
FROM game

我想添加带有目标 + 辅助列的得分列。 请给我一个建议。

使用Ecto.Query.API.fragment/1.

from g in Game,
  select: %{
    goal: g.goal,
    assist: g.assist,
    point: fragment("? + ?", g.goal, g.assist)
  }