Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Questions

Status
Not open for further replies.

sophie123

Programmer
Nov 2, 2004
10
US
If you had a table that had a primary key.. say a ss number and you had one other field in your table that was a date field. What would be the easiest way to find the 2nd most recent date or the second oldest date in the table
 
traditional SQL:

select max(datecol)
from tab
where datecol < (select max(datecol) from tab)


OLAP-function:

select datecol
from tab
qualify rank() over (order by datecol desc) = 2

if datecol is not unique:

select datecol
from (select distinct datecol from tab) dt
qualify rank() over (order by datecol desc) = 2

Dieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top