Loading TOC...

MarkLogic 12 Product Documentation
op.avg

op.avg(
   aggColName as String,
   columndef as ColumnIdentifier,
   [options as String]
) as aggregatedef

Summary

This function averages 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.

Parameters
aggColName The name to be used for the aggregated column.
columndef The column to be aggregated. The column can be named with a string or a column function such as op.col, op.viewCol, or op.schemaCol, or constructed from an expression with the op.as function.
options The options can take a values key with a 'distinct' value to average the distinct values of the column.

Example

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

op.fromView('main', 'expenses')
   .groupBy('Category', op.avg("Average Amount", "Amount"))
   .orderBy('Category')
   .result();
  

Example

(: using 'values' option to average distinct values of column :)
const op = require('/MarkLogic/optic');

op.fromView('main', 'expenses')
   .groupBy('Category', op.avg("Average Amount", "Amount",{"values":"distinct"}))
   .orderBy('Category')
   .result();
  

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