将Postgres查询转换为JPQL

时间:2017-01-02 12:36:45

标签: java postgresql hibernate jpql

如何将PostreSQL以下的查询转换为JPQL?我主要坚持 row_number(),分区,如果是

select p, c from  product p left join 
  (
    select 
    c.product_id, c.id, c.status, c.start_date,
    row_number() over (partition by product_id order by (case status when 'EXPIRED' then 2 else 1 end) asc, start_date desc) as row_number
    from contract c
    order by product_id
  ) c
  on
  p.id = c.product_id and c.row_number = 1 
  order by p.id, c.start_date;

0 个答案:

没有答案