我运行下面的sql查询,以便按日期从表顺序获得不同的数据,这样可以正常工作。
join
这是我的JPARepository查询。
select * from content_details c
inner join(select spendpool_id, max(uploaded_date) as latest
from content_details group by spendpool_id) r on c.uploaded_date = latest
and r.spendpool_id = c.spendpool_id
where c.spendpool_id IN (2,3,4,5)
group by c.spendpool_id order by uploaded_date desc;
但是每当我使用查询注释使用子查询时,运行时的spring数据都无法识别语法并抛出错误。
引起:java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌: (附近,第85栏[SELECT m1.spendpoolId FROM com.beroe.insync2.domain.entities.ContentDetails m1 join(选择 spendpoolId,MAX(更新日期)最新消息来自 com.beroe.insync2.domain.entities.ContentDetails group by spendpoolId) m2在m1.uploadedDate = latest和m dpoolId = m1.spendpoolId在哪里 m1.spendpoolId IN(:spendpoolIds)group by m1.spendpoolId order by m1.uploadedDate desc)]
如何在jpa中完成这项工作?