Reference
?

db.sum

Total a numeric column across matching rows, in SQL.
Query.sum(accessor) → Query<number>

Totals one numeric column in SQL, returning 0 over an empty set. Call it on a table or a filtered query, so filter first, then total the result. Like the other aggregates, it fetches no rows.

Parameters
accessor
(row) => number
RequiredThe numeric column to total.
Sum a column
const revenue = await Orders
  .filter((o) => o.status === 'paid')
  .sum((o) => o.amountCents);