SQL - Finding the maximum date group by id table

前端 未结 1 1828
臣服心动
臣服心动 2020-12-20 00:44

Having a table below, I need to get rows with the maximum date having statut equal 2

REMUN_ID    HISTO_ID   DATE_MAJ                 STATUT
2122        700         


        
相关标签:
1条回答
  • 2020-12-20 01:22
    select remun_id, date_maj
    from (
      select r.*, 
             max(date_maj) over (partition by REMUN_ID) as max_date
      from histo_statut_remun r
    ) 
    where date_maj = max_date
      and statut = 2;
    

    SQLFiddle: http://sqlfiddle.com/#!4/7eb75/1

    0 讨论(0)
提交回复
热议问题