Skip to Main Content

SQL & PL/SQL

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!

Need advice on Oracle SQL Sum by Quarters Year (date)

3413453Mar 12 2017 — edited Mar 26 2017

Hello,

Apologies in the wrong form I did some MS SQL before I am have problems with Oracle syntax

I search for ways to do this I know probably lost of ways to get the results.

Adding Amount by quarters (Q#) Q1, Q2, Q3, Q4

Have a tables Sales

SalesID   Date (01-MON-YYYY) Amount

Select Date, Sum (Amount)

From Sales

ORDER_DATE BETWEEN '01-Jan-13' AND '31-Mar-2013'                 Q1

--ORDER_DATE BETWEEN '01-Apr-2013' AND '30-Jun-2013'           Q2

--ORDER_DATE BETWEEN '01-Jul-2013' AND '30-Sep-2013'             Q3

--ORDER_DATE BETWEEN '01-Oct-2013' AND '31-Dec-2013'           Q4

>>>>

If I run

SELECT order_date, SUM (order_amount ) TOTAL                            This give me Q1 no Total and cannot fun a 4 Dates same time I remember signing functions o=in MS SQL or a declare

ORDER_DATE BETWEEN '01-Jan-13' AND '31-Mar-2013

GROUP BY order_date;

<<<<<<<<

I want results like

                      Q1       Q2           Q3             Q4

                 --------------------------------------------

                    1            45          600             25 |-------------

                    2            45            25             25 | these are Amount of sales by date

                   23          10            25             25  |___________

---------------------------------------------------------

Totals         26           100           650           75

Thank You,

Paul Rozee

p_rozee@hotmail.com

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 23 2017
Added on Mar 12 2017
4 comments
1,500 views