Book Image

EJB 3 Developer Guide

By : Michael Sikora
Book Image

EJB 3 Developer Guide

By: Michael Sikora

Overview of this book

Table of Contents (18 chapters)
EJB 3 Developer Guide
Credits
About the Author
About the Reviewers
Preface
Annotations and Their Corresponding Packages

Aggregate Functions


We can summarize or aggregate data using an aggregate function. For example,

SELECT AVG(a.balance) from Account a

will return the average balance over all accounts. The argument to AVG must be numeric. Note that the return type of the AVG function is Double. As a single value is returned we execute the query using the Query.getSingleResult() method.

The remaining aggregate functions provided by JPQL are listed below.

MAX returns the maximum value of the group given an argument which must correspond to an orderable state-field type. Valid orderable state-field types are numeric types, string types, character types, or date types. The MAX return type is equal to the type of the state-field argument.

MIN returns the minimum value of the group given an argument which must correspond to an orderable state-field type. The MIN return type is equal to the type of the state-field argument.

SUM returns the sum of values of the group given a numeric argument. The return type...