I have a table:
| P_id | Month | Year | Name |
624 09 2009 Test1
600 10 2010 Test2
624 10 2010 Test6
600 09 2011 Test7
-
I want to order my table by
P_iddescending,Yearascending, thenMonthascending -
Based on the order I want the last record for each
P_id.
After step 1 is run:
| P_id | Month | Year | Name |
624 09 2009 Test1
624 10 2010 Test6
600 10 2010 Test2
600 09 2011 Test7
Desired Output:
| P_id | Month | Year | Name |
624 10 2010 Test6
600 09 2011 Test7
You could use
row_number:The subquery is required because you can’t use
row_numberdirectly in thewhereclause.