Loading TOC...

MarkLogic Server 11.0 Product Documentation
op:has-group-key

op:has-group-key(
   $outputColumn as xs:string,
   $column as columnIdentifier
) as map:map

Summary

This aggregate function adds a flag to a grouped row specifying whether a column acted as a grouping key for the row.

The flag column has a value of 0 in result rows belonging to a group that has the group key and a value of 1 in other result rows. The aggregate is useful for the op:group-by-union function in cases where the grouping key is nullable and, thus, null values in the grouping key column are insufficient to distinguish rows grouped on a null value from rows that don't belong to a group with the grouping key.

Parameters
$outputColumn The name to be used for the aggregated flag column.
$column The column to flag as a grouping key. The column can be named with a string or a column parameter function such as op:col or constructed from an expression with op:as.

See Also

Example

xquery version "1.0-ml";

import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

op:from-view("main", "expenses")
    => op:group-by-union(
        (op:group(), op:group(("Category", "Location"))),
        (op:has-group-key("Category"), op:has-group-key("Location"), op:sum("TotalAmount", "Amount"))
         )
    => op:order-by(("Category", "Location"))
    => op:result()
  

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