?
Solved

Oracle Pivot

Posted on 2016-10-13
2
Medium Priority
?
82 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 2000 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

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses

765 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