Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jpa平均值(计数(*)_Jpa_Count_Average - Fatal编程技术网

jpa平均值(计数(*)

jpa平均值(计数(*),jpa,count,average,Jpa,Count,Average,假设我有三个表User、Product和UserProduct。一旦用户购买了产品,就会在UserProduct表中创建一条记录。 我想计算用户购买产品的平均数量。我可以通过mySql RDBMS上的纯SQL实现这一点,如下所示: select avg(c) from (select count(*) as c from user_product up join user u on (up.user_id = u.id) group by u.id) as res 我有没有可能对JPA也这么做

假设我有三个表User、Product和UserProduct。一旦用户购买了产品,就会在UserProduct表中创建一条记录。 我想计算用户购买产品的平均数量。我可以通过mySql RDBMS上的纯SQL实现这一点,如下所示:

select avg(c) from (select count(*) as c from user_product up join user u on (up.user_id = u.id) group by u.id) as res
我有没有可能对JPA也这么做

更新:我知道子查询可能只在WHERE或HAVING子句中使用,但仍然