2.10.2.8.6. JPQL Aggregate Examples

The following query returns the average price of all magazines:

SELECT AVG(mag.price) FROM Magazine mag

The following query returns the sum of all the prices from all the magazines published by 'Larry':

SELECT SUM(mag.price) FROM Publisher pub JOIN pub.magazines mag WHERE pub.firstName = 'Larry'

The following query returns the total number of magazines:

SELECT COUNT(mag) FROM Magazine mag