
op:sum( $outCol as item(), $inCol as item(), [$options as map:map?] ) as map:map
This function adds the non-null values of the column for the rows in the group or row set. The result is used for building the parameters used by the op:group-by function.
The op:sum function differs from the op:add function in that it operates on operates on a group of rows, rather than multiple column values in a row.
xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
at "/MarkLogic/optic.xqy";
let $employees := op:from-view("main", "employees")
let $expenses := op:from-view("main", "expenses")
let $totalexpenses := op:col("totalexpenses")
return $employees
=> op:join-inner($expenses, op:on(
op:view-col("employees", "EmployeeID"),
op:view-col("expenses", "EmployeeID")))
=> op:group-by(op:view-col("employees", "EmployeeID"),
("FirstName", "LastName",
op:sum($totalexpenses,
op:view-col("expenses", "Amount"))))
=> op:order-by(op:view-col("employees", "EmployeeID"))
=> op:result()
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.