I have data like this:
item_no p_no    date        RN()
35917   1220540 2000-04-03  1
35917   1220540 2000-04-18  1
35917   1220540 2001-02-12  1
35917   1220540 2001-03-08  1
35917   1220540 2001-03-19  1
542672  1243288 2000-01-24  1
564575  1243288 2000-01-24  2
549816  1243288 2000-01-24  3
542672  1243288 2000-02-25  1
564575  1243288 2000-02-25  2
549816  1243288 2000-02-25  3
I want to select one record for every p_no, with max date (the most recent record). If there are 2 rows with same p_no and date, i need to check item_no and select record with the highest. Example:
- p_no= 1243288 has two dates- 2000-02-25 and 2000-01-24
- date 2000-02-25 is GREATEST so records with date=2000-02-25 is what I'am looking
- there are 3 records with same group (p_np, date) so i have to select record with largest item_no
- record I am interested with : - 564575 1243288 2000-02-25 2 
I used ROW_NUMBER() to get column RN
row_number() over (partition by p_no, date order by date desc) rnk,
but i have no idea how to use this column and check item_no to select what i need. Is my approach is wrong? Any suggestions?
 
     
     
    