select Max 2 rows for each ID
Hi,
I need a query to display .. MAX Two Rows for all IDs.
The tables allows same IDs(more than One) with diff. data with new UpdatedDate
This is My sample Data ...
CID CType StartDate ExpDate UpdatedDate
--- ---- -(MM/DD/YYYY)- ----------- ------------
1 B1 01/01/2004 03/03/2004 01/02/2004
1 OPT 03/06/2004 03/03/2005 03/10/2004
1 H1 03/01/2005 01/03/2008 03/04/2005
2 B1 10/01/2004 01/09/2005 10/04/2004
2 OPT 01/06/2005 01/03/2006 03/07/2006
2 H1 01/01/2006 01/03/2009 01/04/2006
I need a select query to display the result as follows..
1 H1 03/01/2005 01/03/2008 03/04/2005
2 OPT 10/06/2005 01/03/2006 10/07/2006
2 H1 01/01/2006 01/03/2009 01/04/2006
i.e. 2 MAX Updated rows for each CID.
And display Second Row if diff. between
Second Exp.Date and Current Date is 25.
Plz. Help Me....
Thanks & Regards,
Veeru.
|