JPA标准查询和子查询 [英] JPA criteria query with subquery

查看:144
本文介绍了JPA标准查询和子查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用jpa 2.0条件api表达以下查询.

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.

推荐答案

无法完成.子查询不能在SELECT子句中使用. JPQL查询中有相同的限制.在JPA 2.0规范中,它表示为:

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:

子查询可以在WHERE和HAVING子句中使用.

Subqueries may be used in the WHERE and HAVING clause.

这篇关于JPA标准查询和子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆