Extract the 3 most recent dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mzladyd
    New Member
    • Jun 2007
    • 5

    Extract the 3 most recent dates

    I'm trying to create a view by selecting the 3 most recent dates from a table of dates. Is it possible to do this with max case? Sample code is very much appreciated.

    Thanks!
  • Saii
    Recognized Expert New Member
    • Apr 2007
    • 145

    #2
    Can you post your sample code here so that we can figure out what is missing in it.

    Comment

    • tothiyagarajan
      New Member
      • Jun 2007
      • 1

      #3
      Originally posted by mzladyd
      I'm trying to create a view by selecting the 3 most recent dates from a table of dates. Is it possible to do this with max case? Sample code is very much appreciated.

      Thanks!
      select s.date from
      (
      select dense_rank() over (order by date desc)n,date
      from
      table
      )s
      where s.n<=3

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        the previous is the best solution ,still u can try this simple version

        [CODE=oracle]select * from tablename where rownum <4 order by date_field desc[/CODE]

        You can create the view based on the above query.

        Comment

        • mzladyd
          New Member
          • Jun 2007
          • 5

          #5
          My apology, I didn't fully explain what I am trying to do.
          I have a set of data of employee numbers, events, and close_dates. The data includes several months of data. I only want to extract the most recent 3 dates for each employee. such as

          1001 event1 06/25/2007
          1001 event2 05/31/2006
          1001 event3 04/02/2006
          2002 event1 06/18/2006
          2002 event2 06/11/2005
          2002 event3 03/02/2005

          Then I want to pivot the rows to columns, such as
          1001 event1 06/25/2007 event2 05/31/2006 event3 04/02/2006

          Thanks

          Comment

          Working...