JPA criteria query with subquery

妖精的绣舞 提交于 2020-01-05 12:29:06

问题


I was wondering if it was possible to express the following query with jpa 2.0 criteria api.

simple_table:
user_name(varchar),
bytes_total(bigint),
time_total(bigint)

>select
   user_name, 
   sum(bytes_total),
   sum(bytes_total) * 100 / (select sum(bytes_total) from simple_table),
   sum(time_total),
   sum(time_total) * 100 / (select sum(time_total) from simple_table)
from simple_table
group by user_name

I have everything working except for the two sub-queries. I would like to know whether or not this is possible. Thanks.


回答1:


That cannot be done. Subqueries cannot be used in SELECT clause. Same limitation is in JPQL queries. In JPA 2.0 specification this is expressed as follows:

Subqueries may be used in the WHERE and HAVING clause.



来源:https://stackoverflow.com/questions/11187188/jpa-criteria-query-with-subquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!