将 SQL 查询转换为 JPQL 时遇到问题 (Eclipselink)

发布于 2024-09-29 15:24:51 字数 571 浏览 0 评论 0原文

嘿伙计们,我有以下查询,但我似乎无法将其转换为 JPQL。有效的 SQL 是:

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

我微弱的尝试将其翻译如下:

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

提前感谢您能发出的任何光芒!

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 for any light you can shine!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菊凝晚露 2024-10-06 15:24:51

如果我正确理解您的查询(在具有相同 jobId 的实体中选择具有最大 copyNumber 的实体),则以下操作应该有效:

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

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文