From the course: Java Persistence with JPA and Hibernate
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Aggregate functions - JPA Tutorial
From the course: Java Persistence with JPA and Hibernate
Aggregate functions
- [Instructor] Just as you use aggregate functions in SQL, you can use aggregate functions with JPQL as well. Just to refresh, what are aggregate functions? Well, functions like MIN, MAX, SUM, COUNT, and AVG. All of them can perform a calculation on a set of values and return a single value. All five aggregate functions supported in SQL are supported by JPQL as well. Let's try to use them with simple examples. Let's run mariadb-init.sql script and mariadb-07_04.sql script first. Let's say you want to know the number of books authored by the author Allen. You can use the aggregate function COUNT to find this. If you check in the database, there are two books authored by this author. Author Allen has an ID of two, and there are two books authored by that author, which means you should get the result as two. If you go to the Main class and to the method aggregateFunctions. So your query should be SELECT and you should count the books, so you use COUNT(b). B is the alliance or reference…
Contents
-
-
-
-
-
-
-
-
-
(Locked)
JPQL queries10m 47s
-
(Locked)
Joins with JPQL9m 11s
-
(Locked)
Named queries5m 15s
-
(Locked)
Aggregate functions8m 43s
-
(Locked)
ORDER BY, GROUP BY, and HAVING9m 17s
-
(Locked)
Native queries5m 11s
-
(Locked)
Criteria queries12m 8s
-
(Locked)
Challenge: Art Class Management app, part 51m 4s
-
(Locked)
Solution: Art Class Management app, part 55m 19s
-
(Locked)
-
-