4.8.4 Aggregate Functions in the SELECT Clause The result of a query

may be the result of an aggregate

function applied to a path expression.

The following aggregate functions can

be used in the SELECT clause of a

query: AVG, COUNT, MAX, MIN, SUM.

For all aggregate functions except

COUNT, the path expression that is the

argument to the aggregate function

must terminate in a state-field. The

path expression argument to COUNT may

terminate in either a state-field or a

association-field, or the argument to

COUNT may be an identification

variable.

Arguments to the functions SUM and AVG

must be numeric. Arguments to the

functions MAX and MIN must correspond

to orderable state-field types (i.e.,

numeric types, string types, character

types, or date types).

The Java type that is contained in the

result of a query using an aggregate

function is as follows:

COUNT returns Long.

MAX, MIN return the type of the state-field to which they are applied.

AVG returns Double.

SUM returns Long when applied to state-fields of integral types (other

than BigInteger); Double when applied

to state-fields of floating point

types; BigInteger when applied to

state-fields of type BigInteger; and

BigDecimal when applied to

state-fields of type BigDecimal.

If SUM, AVG, MAX, or MIN is used, and

there are no values to which the

aggregate function can be applied, the

result of the aggregate function is

NULL.

If COUNT is used, and there are no

values to which COUNT can be applied,

the result of the aggregate function

is 0.

The argument to an aggregate function

may be preceded by the keyword

DISTINCT to specify that duplicate

values are to be eliminated before the

aggregate function is applied.

Null values are eliminated before the aggregate function is applied, regardless of whether the keyword DISTINCT is specified.

4.8.4 Aggregate Functions in the SELECT Clause The result of a querymay be the result of an aggregatefunction applied to a path expression.The following aggregate functions canbe used in the SELECT cl... кількістьстудентів адресауніверситету Spring Data JPA 到Dao层在 JPA Repository和CrudRepository之间 Створити服务层якийматимеописаніCRUDоперації 解决方案服务层位于Univercity。
import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.poi.hpsf.Decimal; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.tran.
在使用EJB3.0的 JPA 2.0技术的时候,遇到了一个很蛋疼的问题。 很久以前一直用 EntityManager 下get Result List() 查询 数据,即便一个数据亦是如此,所以要频繁的List.get(0)。新街口get Single Result ()出现了,然后就开始频繁报异常。“No entity found for query 在get Single Result 的源...
private EntityManager entityManager ; public Page<RecordMerchantVO> queryMerchantRecord(QueryRecordReq req) { long start = System.currentTimeMillis(); String sor... getSing Result 查询 不到Object不会 返回 null,而是报错---- JPA 什么设计 解决方案: 用自己弄的类 get Single Result OrNull替代 public static T> T get Single Result OrNull(TypedQueryT> query) { query.s
今天做一个 查询 ,因为确定只 返回 一条记录,所以用的get Single Result ()这个方法,但是这个方法 返回 的是Object类型,那到底Object类型里面是什么内容呢? 先看一下直接在工具中 查询 的结果: 只有一条记录,是id为160105的记录的统计数据,后面三个字段是数字。 如果用System.out.println查看输出的话,结果是:[L java .lang.Object;@2
String sql = "select * from T_ order where ...." EntityManager emread; Query qr = emread.createNativeQuery(sqlres); return List lis
使用get Single Result ()方法时如果没有结果(也就是 返回 null)时习惯思维是应该 返回 null,而get Single Result ()方法中有这么一条语句: @throws EntityNotFoundException if there is no result 也就是说,当他 查询 不到结果时,将会抛出EntityNotFoundException异常,而不是 返回 null。