
op:order-by( $plan as map:map, $keys as item()+ ) as map:map
This method sorts the row set by the specified order definition.
| Parameters | |
|---|---|
| $plan | The Optic Plan. You can either use the XQuery => chaining operator or specify the variable that captures the return value from the previous operation. |
| $keys | The specified column or sortdef output from the op:asc or op:desc function. The column can be named with a string or a column function such as op:col, op:view-col, or op:schema-col, or constructed from an expression with the op:as function. |
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:view-col("expenses", "Category"),
op:sum($totalexpenses,
op:view-col("expenses", "Amount"))))
=> op:order-by(op:view-col("employees", "EmployeeID"))
=> op:result()
xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
at "/MarkLogic/optic.xqy";
let $employees := op:from-view("main", "employees")
return $employees
=> op:select(("EmployeeID","FirstName","LastName","Salary"))
=> op:order-by(op:asc(op:col("Salary")))
=> op:result()
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.