title | url | weight | tags | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
XPath Aggregate Functions |
/refguide/xpath-aggregate-functions/ |
1 |
|
This document describes XPath query aggregate functions.
{{% alert color="warning" %}} These functions are for use in Java code only and must contain full XPath queries as their arguments. {{% /alert %}}
{{% alert color="info" %}}
The functions avg
, max
, min
, and sum
functions must specify a column 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.
{{% /alert %}}
The following XPath query aggregate functions are available:
The avg()
function returns the average of its argument.
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)
The count()
function counts all objects retrieved by the enclosed query and returns the value as an integer.
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'])
The max()
function returns the maximum value of its argument.
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)
The min()
function returns the minimum value of its argument.
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)
The sum()
function returns the sum of its argument.
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)