Skip to content
Advertisement

SQL group by get latest results

My question is in the picture:

SQL query

Please see the picture

Advertisement

Answer

if you need the last rev by num and week for each po_num you should use a subquery for max ver

    select * 
    from  table a
    inner join  (

      select    max(rev) max_rev
               , week
               , Po_num
           from  table
           group by week, Po_num
    ) t on t.max_rev  = a.rev 
            and t.po_num  = a.po_num  
            and t.week  = a.week 
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement