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?
Need help with basic sql oracle queries?
Collapse
X
-
Pls check below SQL
Let me know if any issues with above SQL.Code:SELECT ROWNUM, od.* FROM (SELECT * FROM orderdtls ORDER BY orderdate DESC) od WHERE orderdate <= SYSDATE AND ROWNUM <= 45 -
Try This:
[code=oracle]
SELECT * FROM order_details WHERE TRUNC(order_dat e) >= TRUNC(SYSDATE) - 45;
[/code]Comment
-
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
Comment