Skip to Main Content
  • Questions
  • get 3 consecutive dates (based on sys date) in a single column and map it with another Table's column

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Raghu.

Asked: April 09, 2018 - 3:56 pm UTC

Last updated: April 11, 2018 - 3:28 am UTC

Version: 18.1.0.095.1630

Viewed 1000+ times

You Asked

Hi,

I need to show Quantity sold for three consecutive days (yesterday, today, tomorrow).
So, date should be the first column and Quantity being second.

Desired Output
--------------
Date Qty
.... ...
8/4/2018 10
9/4/2018 20
10/4/2018 30

Need to use SysDate for getting the date. I tried as below and able to get the quantity sold for single date.

select sysdate, count(Order_id) as Qty from Orders;

Please note that I can't use Union in my scenario.

Kindly let me know if this can be achieved in any way.

Thanks in advance.


with LiveSQL Test Case:

and Connor said...

SQL> with three_rows as
  2   ( select trunc(sysdate)-2+rownum dte from dual connect by level <= 3 )
  3  select * from three_rows;

DTE
---------
09-APR-18
10-APR-18
11-APR-18


You can then join "THREE_ROWS" to anything you like.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Raghu Nekkalapu, April 10, 2018 - 9:29 am UTC

Hi Connor,

Thank you for the solution.
This fits perfectly in my real time logic.
Connor McDonald
April 11, 2018 - 3:28 am UTC

glad we could help

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.