Loading TOC...

MarkLogic 10 Product Documentation
op.desc

op.desc(
   columndef as String
) as sortdef

Summary

This function sorts the rows by the values of the specified column in descending order. The results are used by the prototype.orderBy function.

Parameters
columndef The column by which order the output.

Example

// Calculate the total expenses for each employee and return results in order of total
// expenses, highest to lowest.

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', expenses.col('Category'),
    op.sum(totalexpenses, expenses.col('Amount'))])
   .orderBy(op.desc('totalexpenses'))
Plan.result();
  

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