I have a query I run to tell me the latest note for active participants:
select notes.applicant_id,
reg.program_code,
reg.last_name,
reg.first_name,
reg.status_cd,
MAX(notes.service_date) as "Last Note"
from reg inner join notes on reg.applicant_id=notes.applicant_id
where reg.status_cd='AC'
group by notes.applicant_id, reg.program_code,
reg.last_name, reg.first_name, reg.reg_date,
reg.region_code, reg.status_cd
order by MAX(notes.service_date)
But I would also like this query to give me the result of the note.service_date
just prior to the max service_date
as well.
Results would look like this
notes.applicant_id reg.last_name reg.first_name reg.status_cd Last Note Prior Note
12345 Johnson Lori AC 01-NOV-2011 01-OCT-2011
I am working in oracle.