How to use XQuery aggregate function in XML

In this article, I am going to explain aggregate function in XQuery.
  • 2841

Aggregate Functions

The built-in aggregate functions are defined below-

  • count Function

    The count function returns the total number of value in a sequence.

Syntax of count function

fn:count($args as item()*) as xs:integer


Example of count function
 

fn:count(2,4,5) returns 3.

  • avg Function

    The avg function returns the average of the value in a sequence.

Syntax of avg function
 

fn:avg($arg as xdt:anyAtomicType) as xdt:anyAtomicType


Example of avg function
 

fn:avg(1,2,3) returns 2.

  • min Function

    The min function returns the minimum of the values in a sequence.

Syntax of min function
 

fn:min($arg as xdt:anyAtomicType) as xdt:anyAtomicType


Example of min function
 

fn:min(1,2,3) returns 1.
fn:min('c','d','e') returns c.

  • max Function

    The max function returns the maximum of the values in a sequence.

Syntax of max function
 

fn:max($arg as xdt:anyAtomicType) as xdt:anyAtomicType


Example of max function
 

fn:max(1,2,3) returns 3.
fn:max('c','d','e') returns e.

  • sum Function

    The sum function returns sum of all values in a sequence.

Syntax of sum function
 

fn:sum($arg as xdt:anyAtomicType) as xdt:anyAtomicType


Example of sum function
 

fn:sum(1,2,3) returns 6.

Further Readings

You may also want to read these related articles:

Ask Your Question 

Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.