我为 MySQL 编写了以下查询:
SELECT subquery.t1_column1,
subquery.t2_id,
MAX(subquery.val)
FROM (
SELECT t1.column1 as t1_column1,
t1.id_t2 AS t2_id,
count(1) AS val
FROM table1 t1
INNER JOIN table2 t2
ON t2.id = t1.id_t2
GROUP BY t1.id_t2
) subquery
GROUP BY t1_column1
我想把它翻译成 JPA(JPQL 或标准查询)。
我不知道如何制作这个 max(count) 东西,而且 JPA 似乎不喜欢 SELECT FROM SELECT ...
如果有人有原生查询以外的想法(我现在就去做),那就太好了。