Home » SQL & PL/SQL » SQL & PL/SQL » To divide data that is shown in ONE column to THREE columns (Oracle 10g)
To divide data that is shown in ONE column to THREE columns [message #308184] Fri, 21 March 2008 14:57 Go to next message
cores
Messages: 15
Registered: March 2008
Junior Member
Hi,
Can you please give me suggestion how to show funding in three columns, for step = 11, step = 12, step = 16?

select * from fund_steps_vw;

Project Step   Funding
1	12	111
1	16	111
3	12	1
3	16	1
7	12	333
7	16	333
11	12	32423
12	11	125

I need to receive:

Project Step   Fund_12  Fund_16   Fund_11
1       12       111
1       16                111
3       12       1
3       16                  1
7       12       333
7       16                333
11      12       32423
12      11                           125      


Thank you



[moderator edit: code tags added; next time please do it yourself]

[Updated on: Fri, 21 March 2008 15:20] by Moderator

Report message to a moderator

Re: To divide data that is shown in ONE column to THREE columns [message #308185 is a reply to message #308184] Fri, 21 March 2008 15:03 Go to previous messageGo to next message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter) and align the columns in result.
Use the "Preview Message" button to verify.

What is the difference between input and output? I see none but the header names.

Regards
Michel

[Updated on: Fri, 21 March 2008 15:03]

Report message to a moderator

Re: To divide data that is shown in ONE column to THREE columns [message #308187 is a reply to message #308184] Fri, 21 March 2008 15:22 Go to previous messageGo to next message
Barbara Boehmer
Messages: 8636
Registered: November 2002
Location: California, USA
Senior Member
If you search for PIVOT on this forum, you will find many examples. If using Oracle 11g, you can also use the new PIVOT syntax found in the online documentation.
Re: To divide data that is shown in ONE column to THREE columns [message #308189 is a reply to message #308185] Fri, 21 March 2008 15:28 Go to previous messageGo to next message
cores
Messages: 15
Registered: March 2008
Junior Member
Michel, sorry, you can see now.

Thanks to Moderator's editing and code tags adding to my message.



Re: To divide data that is shown in ONE column to THREE columns [message #308190 is a reply to message #308187] Fri, 21 March 2008 15:32 Go to previous messageGo to next message
cores
Messages: 15
Registered: March 2008
Junior Member
Thanks, Barbara. No,I am using Oracle 10g.

So, I will look for examples for Pivot.
Re: To divide data that is shown in ONE column to THREE columns [message #308191 is a reply to message #308190] Fri, 21 March 2008 16:50 Go to previous messageGo to next message
cores
Messages: 15
Registered: March 2008
Junior Member
Thanks,
found solution.
Re: To divide data that is shown in ONE column to THREE columns [message #308195 is a reply to message #308191] Fri, 21 March 2008 19:52 Go to previous messageGo to next message
ravi214u
Messages: 153
Registered: February 2008
Location: CANADA
Senior Member
U can Use this query also
SQL> select project,step, 
case when step=12 then fund end as fund_12,
case when step=16 then fund end as fund_16,
case when step=11 then fund end as fund_11 
from fund order by project,step;

    PROJECT        STEP    FUND_12    FUND_16    FUND_11
----------- ----------- ---------- ---------- ----------
          1          12        111            
          1          16                   111 
          3          12          1            
          3          16                     1 
          7          12        333            
          7          16                   333 
         11          12      32423            
         12          11                              125

8 rows selected
Re: To divide data that is shown in ONE column to THREE columns [message #308208 is a reply to message #308195] Sat, 22 March 2008 01:49 Go to previous messageGo to next message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
1/ Please don't use IM/SMS speak
2/ Don't put solution only hint or clue as requested in OraFAQ Forum Guide, "Responding to Posts" section:
Quote:
When responding to questions, if it is obviously a student with a homework assignment or someone else just learning, especially in the homework and newbies forums, it is usual to provide hints or clues, perhaps links to relevant portions of the documentation, or a similar example, to point them in the right direction so that they will research and experiment on their own and learn, and not provide complete solutions to problems. In cases where someone has a real-life complex work problem, or at least it may seem complex to them, it may be best to provide a complete demo and explanation.


Regards
Michel
Re: To divide data that is shown in ONE column to THREE columns [message #308234 is a reply to message #308208] Sat, 22 March 2008 10:02 Go to previous message
ravi214u
Messages: 153
Registered: February 2008
Location: CANADA
Senior Member
Sorry Michel i will remember next time.
Previous Topic: ORA-06502,urgent help req.
Next Topic: Oracle dates
Goto Forum:
  


Current Time: Sat Dec 10 20:30:17 CST 2016

Total time taken to generate the page: 0.24872 seconds