XPath Aggregate Functions
Introduction
This document describes XPath query aggregate functions.
The functions avg
, max
, min
, and sum
functions must specify an attribute in the query to aggregate (for example, /TotalPrice
).
The functions avg
, max
, min
, and sum
functions must also specify an attribute that has a numeric type.
The following XPath query aggregate functions are available:
avg
The avg()
function returns the average of its argument.
Examples
This query returns the average total price of all placed orders:
avg(//Sales.Order/TotalPrice)
This query returns the average total price of all orders placed by a customer named “Jansen”:
avg(//Sales.Order[Sales.Customer_Order/Sales.Customer = 'Jansen']/TotalPrice)
count
The count()
function counts all objects retrieved by the enclosed query and returns the value as an integer.
Examples
This query returns a count of all the placed orders:
count(//Sales.Order)
This query returns a count of all the orders placed by a customer named “Jansen”:
count(//Sales.Order[Sales.Customer_Order/Sales.Customer/Name = 'Jansen'])
max
The max()
function returns the maximum value of its argument.
Examples
This query returns the highest total price found in any object:
max(//Sales.Order/TotalPrice)
This query returns the highest total price of an order placed by a customer named “Jansen”:
max(//Sales.Order[Sales.Customer_Order/Sales.Customer/Name = 'Jansen']/TotalPrice)
min
The min()
function returns the minimum value of its argument.
Examples
This query returns the lowest total price found in any object:
min(//Sales.Order/TotalPrice)
This query returns the lowest total price of an order placed by a customer named “Jansen”:
min(//Sales.Order[Sales.Customer_Order/Sales.Customer/Name = 'Jansen']/TotalPrice)
sum
The sum()
function returns the sum of its argument.
Examples
This query returns the sum of the total prices of all placed orders:
sum(//Sales.Order/TotalPrice)
This query returns the sum of the total prices of all the orders placed by a customer named “Jansen”:
sum(//Sales.Order[Sales.Customer_Order/Sales.Customer/Name = 'Jansen']/TotalPrice)