op.sum( aggColName as String, columndef as String, [options as String] ) as aggregatedef
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 prototype.groupBy 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.
// Calculate the total expenses for each employee and return results in order of employee number. const op = require('/MarkLogic/optic'); const employees = op.fromView('main', 'employees'); const expenses = op.fromView('main', 'expenses'); const totalexpenses = op.col('totalexpenses'); const Plan = employees.joinInner(expenses, op.on(employees.col('EmployeeID'), expenses.col('EmployeeID'))) .groupBy(employees.col('EmployeeID'), ['FirstName', 'LastName', op.sum(totalexpenses, expenses.col('Amount'))]) .orderBy('EmployeeID') Plan.result();
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.