How to write MAX and OVER (PARTITION BY) functions in JPA query

限于喜欢 提交于 2020-04-11 05:31:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!