I have a table that holds Client_ID and Communication_Date I would like to produce below table. Table should list previous and last communication dates.Is there any way to write a query for it? Any help will be appreciated.
Thanks
ORIGINAL TABLE
ID Client_ID Communication_date
1 1001 01-05-2013
2 1002 01-05-2013
3 1003 02-05-2013
4 1001 09-05-2013
5 1001 14-05-2013
6 1002 18-05-2013
7 1002 25-05-2013
Requested Table
Client_ID PreviousCom_Date LastCom_date
1001 01-05-2013 09-05-2013
1001 09-05-2013 14-05-2013
1002 01-05-2013 18-05-2013
1002 18-05-2013 25-05-2013
1003 02-05-2013 Null or whatever
select client_id, min(com_date) as first_com, max(com_date) as last_com from foobar where com_date < ? and com_date > ? group by client_id