Need help with basic sql oracle queries?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paganini
    New Member
    • Aug 2009
    • 1

    Need help with basic sql oracle queries?

    I've got a table, lets say table name is A and inside there's "date" column and "order name" column. How to retrieve the order for the last 45 days without knowing what're the dates inside the column?
  • OraMaster
    New Member
    • Aug 2009
    • 135

    #2
    Originally posted by paganini
    I've got a table, lets say table name is A and inside there's "date" column and "order name" column. How to retrieve the order for the last 45 days without knowing what're the dates inside the column?
    Pls check below SQL

    Code:
    SELECT ROWNUM, od.*
      FROM (SELECT   *
                FROM orderdtls
            ORDER BY orderdate DESC) od
     WHERE orderdate <= SYSDATE AND ROWNUM <= 45
    Let me know if any issues with above SQL.

    Comment

    • amitpatel66
      Recognized Expert Top Contributor
      • Mar 2007
      • 2358

      #3
      Try This:

      [code=oracle]

      SELECT * FROM order_details WHERE TRUNC(order_dat e) >= TRUNC(SYSDATE) - 45;

      [/code]

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Originally posted by OraMaster
        Pls check below SQL

        Code:
        SELECT ROWNUM, od.*
          FROM (SELECT   *
                    FROM orderdtls
                ORDER BY orderdate DESC) od
         WHERE orderdate <= SYSDATE AND ROWNUM <= 45
        Let me know if any issues with above SQL.
        why use rownum ?

        Question is not to retrieve last 45 records but of data of last 45 days.
        There may be more that one entry in the database per day.

        How rownum will help in that scenario ?

        Comment

        Working...