问题
I need to get one column(revision) maximum value based on another column(drawingNumber). Can anyone tell me the JPA query for this functionality.
I have written the following query and this query is not working.
Please help me how to write MAX and OVER (PARTITION BY) functions in JPA query.
@Query("select dr FROM
(SELECT MAX(dr.revision) over (PARTITION BY d.drawing_number) AS latest_revision
FROM DrawingRate dr
JOIN dr.drawing d
JOIN d.modifiedBy mb
WHERE mb.Id=:Id
OR piu.Id=:Id
ORDER BY d.localModifiedOn DESC NULLS LAST
) WHERE dr.revision = :latest_revision")
This Spring data JPA query is not working while running this showing the following error:
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ( near line 1, column 16 [select dr from (select max(dr.revision) over (partition by d.drawing_number) AS last_enrolment_date from entity.DrawingRate dr join dr.drawing d JOIN d.modifiedBy mb left join dr.modifiedBy u WHERE mb.Id=:IdOR piu.Id=:Id order by d.localModifiedOn DESC NULLS LAST) WHERE dr.revision = :latest_revision]
Please help me how to write MAX and OVER (PARTION BY) functions in JPA query.
来源:https://stackoverflow.com/questions/55242187/how-to-write-max-and-over-partition-by-functions-in-jpa-query