开发者

Trouble converting SQL Query into JPQL (Eclipselink)

开发者 https://www.devze.com 2023-01-22 21:08 出处:网络
Hey guys,I have the following query and for the life of me I can\'t seem to translate it into JPQL.The working SQL is:

Hey guys, I have the following query and for the life of me I can't seem to translate it into JPQL. The working SQL is:

select * from TB_PRINT_DETAIL y inner join 
(select JOB_ID,max(COPY_NUM) MAX_COPY_NUM from TB_PRINT_DETAIL  group by JOB_ID  ) x
on y.JOB_ID = x.JOB_ID and y.COPY_NUM = x.MAX_COPY_NUM

My feeble attempt at translating it is as follows:

select o from PrintDetailEntity o inner join (select o2.jobId, max(o2.copyNumber) as
maxCopyNum from PrintDetailEntity o2 group by o2.jobId ) as x on o.jobId = o2.jobId and
o.copyNum = o2.maxCopyNum where o.printSuppressionReasonEntity is null

Thanks in advance f开发者_JAVA技巧or any light you can shine!


If I understand your query right (select entities that have the biggest copyNumber among the entites with the same jobId), the following should work:

SELECT o 
FROM PrintDetailEntity o 
WHERE o.copyNumber = 
    (SELECT MAX(e.copyNumber) FROM PrintDetailEntity e WHERE o.jobId = e.jobId)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号