Solved

Oracle Pivot

Posted on 2016-10-13
2
32 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
2 Comments
 
LVL 76

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now