Skip to Main Content

SQL Developer

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

To get the data for last 3 day trend

grakesOct 26 2015 — edited Oct 31 2015

Hi,

Could you please help me to find out the data based on the last 3 day trend?

Based on the below sql I can get the total count for last 3 day trend, but I don't know how to get the total count without using UNION ALL. It's taking too much time to get the result. Please help me to find out simple method.

Select TRUNC(SYSDATE) 3Day_Trend, count(Created_Date) from Order

Where Created_Date <= TRUNC(SYSDATE)

UNION ALL

Select TRUNC(SYSDATE)-1 3Day_Trend, count(Created_Date) from Order

Where Created_Date <= TRUNC(SYSDATE)-1

UNION ALL

Select TRUNC(SYSDATE)-2 3Day_Trend, count(Created_Date) from Order

Where Created_Date <= TRUNC(SYSDATE)-2

For Example,

Name      Order_Id      Created_Date

A                1                08/21/2015

A                2                09/18/2015

A                3                10/25/2015

B                1                08/12/2015

B                2                08/23/2015

B                3                09/14/2015

B                4                10/26/2015

C                1                10/24/2015

C                2                10/25/2015

C                3                10/26/2015

Expected output:

3Day_Trend      Total_Count

10/26/2015           10

10/25/2015            8

10/24/2015            6

Thanks,

Guna

This post has been answered by aJohny on Oct 26 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 28 2015
Added on Oct 26 2015
5 comments
1,070 views