I have a table which may have multiple records for each person.
Roughly speaking the table has:
name code start_date end_date class
Bob 1234 20000101 20001231 P
Bob 1234 20010101 20011231 M
Bob 1234 20020101 20020604 C
Bob 1234 20020604 99991231 M*
Sue 2234 20000101 20001231 P
Sue 2234 20010101 20010331 C
Sue 2234 20020401 20020604 M*
Sue 2234 20020605 20030202 U
Sue 2234 20030203 99991231 M
I want the last row for each person where the class is 'M' and the start_day is less than today.
So I essentially want the MAX(record) for each person where class = 'M' and start_date <= run_date. The ones noted above with an astrick by the 'M' would be the ones I want.
Ideas?
Roughly speaking the table has:
name code start_date end_date class
Bob 1234 20000101 20001231 P
Bob 1234 20010101 20011231 M
Bob 1234 20020101 20020604 C
Bob 1234 20020604 99991231 M*
Sue 2234 20000101 20001231 P
Sue 2234 20010101 20010331 C
Sue 2234 20020401 20020604 M*
Sue 2234 20020605 20030202 U
Sue 2234 20030203 99991231 M
I want the last row for each person where the class is 'M' and the start_day is less than today.
So I essentially want the MAX(record) for each person where class = 'M' and start_date <= run_date. The ones noted above with an astrick by the 'M' would be the ones I want.
Ideas?