[askdba] SQL Help

  • From: Rick_Cale@xxxxxxxxxxxxxx
  • To: askdba@xxxxxxxxxxxxx
  • Date: Tue, 2 Nov 2004 16:43:54 -0500




Hi,

I have need some help on an sql statement.

I have a table(tab1) field1,field2,field3.  Field3 is a date field.

There are more that one date for field1, field2 combination.

I want to be able to get the max(field3) for field1,field2 which is easy
enough.  But I also want to get the next highest field3 date for the same
field1,field2

I would like the output to be

field1,field2,Max(field3),NextHighest(field3)

ex.

1, 2, 11/02/2004, 10/30,2004
4, 5, 09/01/2004, 08/13/2004


Sample table data for the above may be

1     2     11/02/2004
1     2     10/30/2004
1     2     09/02/2002
1     2     06/06/2001
4     5     09/01/2004
4     5     08/13/2004
4     5     02/02/1999

Any ideas how I can accomplish the above?  Oracle 8i SE


Rick Cale
Database Administrator
Team Health, Inc.
865-293-5425
Rick_Cale@xxxxxxxxxxxxxx


Other related posts: