Solved

Oracle Pivot

Posted on 2016-10-13
2
68 Views
Last Modified: 2016-10-13
Greeting,

I have a select stmt with the following output.
empID   FirstName  LastName Work_type Rate
00001     John             Smith            RE             20
00001     John             Smith             OT            40
00002     Bob              Jackson         RE              25

I'd like to make the change to get the following output
empID       FirstName     LastName     RE_Rate     OT_Rate
00001          John               Smith               20                40
00002          Bob                Jackson            25

Thanks in advance.
0
Comment
Question by:mrong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 41842118
untested but try something like this:
select empID, FirstName, LastName,
   max(case when work_type='RE' then rate end) re_rate,
   max(case when work_type='OT' then rate end) ot_rate
from your_table
group by empID, FirstName, LastName


Note:  You cannot have a dynamic number of columns.
0
 

Author Closing Comment

by:mrong
ID: 41842160
Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question