DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: TOP N DATE S

  1. #1
    Join Date
    Sep 2001
    Posts
    24

    Red face

    HI,

    I want top n dates from a table. Say there are 10 different dates and the result must be the top 3 unique dates (in desc order).

    Regards
    Bunny.

  2. #2
    Join Date
    Jan 2001
    Posts
    153
    select *
    from
    (select
    allcols from yourtable
    order by datecol desc)
    where
    rownum <=3

    Rgds
    Vijay.s

  3. #3
    Join Date
    Jan 2001
    Posts
    153
    sorry a DISTINCT got missed..

    Rgds
    Vijay.s

  4. #4
    Join Date
    Sep 2001
    Posts
    24
    Hi,
    The table has got code , date and value. The value has to be summed datewise and for my given date the latest three days must be fetched .If i use the ROWNUM then the results will be wrong as GROUP BY has to be used.

    Regards
    Bunny
    Shyla

  5. #5
    Join Date
    Mar 2001
    Location
    Reading, U.K
    Posts
    598
    hi,
    u hv 2 use RANK() function.

    select distinct statement_date from (select statement_date, dense_rank() over (order by statement_date DESC) as rnk1
    from account_Statement)
    where rnk1 < 4
    /

    VBHASKAR CODE IS CORRECT U HV 2 ADD DISTINCT ALONE
    select *
    from
    (select DISTINCT
    allcols from yourtable
    order by datecol desc)
    where
    rownum <=3

    JEGANNATHAN S
    Cheers!
    OraKid.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width