Home » SQL & PL/SQL » SQL & PL/SQL » Help on query (merged 2) 10.2.0.1
Help on query (merged 2) 10.2.0.1 [message #415334] Mon, 27 July 2009 05:22 Go to next message
dba_raf
Messages: 13
Registered: December 2005
Junior Member
Hi,
I've this table T_MONTH_COST

COD_ID...........X_YEAR........X_MONTH........SUM_COST
22...............2009............01..........2000
33...............2009............02..........5000
35...............2009............03..........8000
37...............2009............04..........11000
39...............2009............05..........14000
41...............2009............06..........17000
43...............2009............07..........20000
45...............2009............08..........23000
47...............2009............09..........26000
49...............2009............10..........29000
51...............2009............11..........32000
53...............2009............12..........35000

66...............2008............01..........1000
67...............2008............02..........2000
68...............2008............03..........3000
69...............2008............04..........4000
70...............2008............05..........5000
71...............2008............06..........6000
72...............2008............07..........7000
73...............2008............08..........8000
74...............2008............09..........9000
75...............2008............10..........10000
76...............2008............11..........11000
77...............2008............12..........12000
...................................................more 1000 records

I'd like to write a query with this output:

COD_ID.....X_YEAR.....X_MONTH.....SUM_COST1....SUM_COST2...SUM_COST3.....SUM_COST4.....SUM_COST5.....SUM_COST6.....SUM_COST7.....SUM_ COST8.....SUM_COST9.....SUM_COST10.....SUM_COST11...SUM_COST12
22..........2009.........01..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000
33..........2009.........02..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000
35..........2009.........03..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000
37..........2009.........04..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000
39..........2009.........05..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000
41..........2009.........06..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000
43..........2009.........07..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000
45..........2009.........08..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000
47..........2009.........09..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000
49..........2009.........10..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000
51..........2009.........11..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000
53..........2009.........12..........2000.......5000........8000..........11000.........14000.........17000..........20000.......2300 0..........26000.........29000.........32000..........35000

For X_MONTH=01 SUM_COST=2000 in column SUM_COST1
For X_MONTH=02 SUM_COST=5000 in column SUM_COST2
For X_MONTH=03 SUM_COST=8000 in column SUM_COST3
................................................
...............................................
For X_MONTH=12 SUM_COST=35000 in column SUM_COST12

How can I write this query??

Thanks in advance!
Re: Help on query (merged 2) 10.2.0.1 [message #415337 is a reply to message #415334] Mon, 27 July 2009 05:32 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
Instead of the ....., you could have given code tags. Read Forum Guide, if you don't know how to do that.

Also you could have given the DDL and DMLs.

What's your query (whatever you have tried)?

By
Vamsi
Re: Help on query (merged 2) 10.2.0.1 [message #415350 is a reply to message #415334] Mon, 27 July 2009 05:56 Go to previous message
Michel Cadot
Messages: 64121
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
In addition, this is a standard PIVOT query (search for this word).

Regards
Michel
Previous Topic: create table query with auto increment for one column
Next Topic: EXECUTE IMMEDIATE
Goto Forum:
  


Current Time: Wed Dec 07 03:04:57 CST 2016

Total time taken to generate the page: 0.05200 seconds