2013-05-21 49 views

回答

2

有兩種方法,既可以使用由一組,或子選擇的選擇子句中,

Select Count(p), p.status from Person p group by p.status 

,或者選擇子句中

Select (Select Count(p) from Person p where p.status = Status.Single), (Select Count(p) from Person p where p.status = Status.Married), (Select Count(p) from Person p where p.status = Status.Divorced) 

但子選擇是不由JPA支持(至少JPA 2.0,2.1我相信),EclipseLink 2.4或更高版本確實支持這一點。