Skip to content

XQuery avg Function

How to calculate the average of numeric values in a sequence using the XQuery avg function with syntax and practical examples.

XQuery avg Function

The avg function is used to get the average of total items present in a sequence.

Syntax

avg($seq as item()*)

Input Parameters

  • $seq is the provided sequence. A sequence can contain 0 or more items.

Example

XQuery Expressionxquery
let $items := (1,2,3,4,5,6)
let $avg := avg($items)
return
   <result>
      <avg>{$avg}</avg>
   </result>
Outputxml
<result>
   <avg>3.5</avg>
</result>
Navigation