Home » SQL & PL/SQL » SQL & PL/SQL » I am perplexed on how to do this...pls help...
I am perplexed on how to do this...pls help... [message #20151] Wed, 01 May 2002 17:51 Go to next message
knenk
Messages: 2
Registered: May 2002
Junior Member
Hi!
I am perplexed on how to do this...pls help...
Given the Table below
---------------------------------
Sales | Date_column
8000 | 2000/01/22 19:31:39
7000 | 2001/01/22 19:31:39
7000 | 2001/02/22 19:31:39
3000 | 2001/03/22 19:31:39
5000 | 2002/02/22 19:31:39
4002 | 2002/03/01 16:10:46

I want to create a query that will return something like this...

------------------------------------
Year___&#124___Jan_Sales&#124___Feb_Sales Mar_Sales ..... Dec
2000___&#124________8000__
2001___&#124________7000__&#124_______7000________3000
2002___&#124________________&#124_______5000________4002

Your help is very much appreciated...
Thanks....

-knenk
Re: I am perplexed on how to do this...pls help... [message #20152 is a reply to message #20151] Wed, 01 May 2002 21:53 Go to previous message
Shankar. V
Messages: 5
Registered: April 2002
Junior Member
Try this query:
***************
Note: dos -> Date of Sales, salamt->sales amount
Hint: You can improve this by adding all 12 months.

select to_char(dos,'yyyy') year,
sum(decode(to_char(dos,'mm'),'01',nvl(salamt,0),0)) jan_sales,
sum(decode(to_char(dos,'mm'),'02',nvl(salamt,0),0)) feb_sales,
sum(decode(to_char(dos,'mm'),'03',nvl(salamt,0),0)) mar_sales
from sales group by to_char(dos,'yyyy');
Previous Topic: ALL Keyword
Next Topic: Re: Apriori algorithm - Data Mining
Goto Forum:
  


Current Time: Thu Apr 25 10:17:46 CDT 2024