Loading TOC...

MarkLogic 12 Product Documentation
op.add

op.add(
   numericExpression as String,
   numericExpression as String
) as numericExpression

Summary

This function returns the sum of the specified numeric expressions. In expressions, the call should pass the result from an op.col function to identify a column.

The op.add function differs from the op.sum function in that it operates on operates on multiple column values in a row, rather than a group of rows.

As a convenience, the function allows passing any number of expression arguments in the form: op.add(expr1, expr2, ..., exprN)

Parameters
numericExpression The left numeric expression. It can be a number, a column function such as op.col, op.viewCol, or op.schemaCol, or expressions.
numericExpression The right numeric expression. It can be a number, a column function such as op.col, op.viewCol, or op.schemaCol, or expressions.

Example

const op = require('/MarkLogic/optic');

const employees = op.fromView('main', 'employees');

employees.offsetLimit(op.param('start'), op.param('length'))
	   .select(['EmployeeID', 
                op.as('incremented', 
                       op.add(op.col('EmployeeID'), op.param('increment')))
               ])
	   .result(null, {start:1, length:2, increment:1});

  

Example

const op = require('/MarkLogic/optic');

const employees = op.fromView('main', 'expenses');

employees.select(['EmployeeID', 
                op.as('TotalExpenses', 
                       op.add(op.col('Entertainment'), op.col('Health'), op.col('Transport'))
               ])
	   .result();

  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.