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

Thread: One Small Problem

  1. #1
    Join Date
    Oct 2000
    Posts
    6

    Unhappy

    Dear friends...

    Facing one small problem. I have following data in a table

    Rec No Cust_id Date
    ------- -------- -----
    1 1001 01/01/2001 10.20.00
    2 1001 01/01/2001 10.30.00
    3 1001 01/01/2001 09.30.00


    I need the record - one less than max date. i.e. Rec No. 1

    Please advise what query/PL SQL i should run.

    Thank in advance

    Nkakrani


  2. #2
    Join Date
    Sep 2000
    Posts
    19
    select x.recno from <tablename> x where 2 = (select count(*) from <tablename> y where x.<date_column> <= y.<date_column>)

  3. #3
    Join Date
    Feb 2001
    Posts
    4
    I'm sure there's a number of different solutions and this one is most probably not the best

    SELECT *
    FROM test_sql A
    WHERE A.cust_date = (
    SELECT MAX(B.cust_date)
    FROM test_sql B
    WHERE B.cust_date < (
    SELECT MAX(C.cust_date)
    FROM test_sql C))

  4. #4
    Join Date
    Oct 2000
    Posts
    123
    One clear way is:

    select ename, empno, hiredate
    from ( select ename, empno, hiredate, rownum r
    from ( select ename, empno, hiredate
    from emp
    order by hiredate DESC )
    where rownum <= 2 )
    where r = 2

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