我有一个试图转换为 JPQL 的 SQL 查询。查询如下:
SELECT *
FROM MyTable
WHERE (myFirstColumn, mySecondColumn) IN (
SELECT myFirstColumn, max(mySecondColumn)
FROM MyTable
GROUP BY myFirstColumn
)
我的转换尝试很简单:
select myObject
from MyObject as myObject
where (myObject.myFirstValue, myObject.mySecondValue) in (
select subMyObject.myFirstValue, max(subMyOject.mySecondValue)
from MyObject as subMyObject
group by subMyObject.myFirstValue
)
MyObject 映射到 MyTable(使用注释)。
如果我了解 IN 语句中的 JPQL 文档(http://openjpa.apache.org/builds/1.2.3/apache-openjpa/docs/jpa_langref.html#jpa_langref_in),我真的不确定我是否知道,这种直接转换是不可能的。还有其他方法吗?