Solved

Oracle Pivot

Posted on 2016-10-13
2
59 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL GROUP BY 6 82
SQL Rewrite without the NULLIF 4 25
SQL Query help 3 25
Union & Crosstab qrys 101! 6 58
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

730 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