Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query

Status
Not open for further replies.

DKL01

Programmer
Sep 14, 2000
233
US
Hi,

I have Oracle table with several columns. One of the fields is Order_Date.


Order_Date
24-OCT-2000
23-NOV-2000
08-DEC-2000
10-JAN-2001
04-MAR-2001
05-APR-2001
05-JUL-2001
11-NOV-2001
09-DEC-2001


I need to write a query which returns previous six orderdates (including
the date passed). For instance, if I pass 09-DEC-2001, the query should
return

09-DEC-2001
11-NOV-2001
05-JUL-2001
05-APR-2001
04-MAR-2001
10-JAN-2001

And if I pass 05-APR-2001, the query should return

05-APR-2001
04-MAR-2001
10-JAN-2001
08-DEC-2000
23-NOV-2000
24-OCT-2000

I would appreciate if somebody could help to write the query.

Thanks
 
Code:
SELECT orderdate
FROM (SELECT orderdate
FROM sales_order
WHERE orderdate <= TO_DATE ('05-APR-2001', 'DD-MON-YYYY')
ORDER BY orderdate DESC)
WHERE ROWNUM < 7
ORDER BY orderdate ASC
[\code]

You have to put the guts of the thing in an inline view with an ORDER BY clause for this to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top