We help IT Professionals succeed at work.
Get Started

Pivoting oracle table

LuckyLucks
LuckyLucks asked
on
180 Views
Last Modified: 2017-04-03
Hi

I have a table with 3 columns of data and would like to pivot it as the result shown below, please help me with the pivot or other syntax.

CREATE TABLE pivot_test (
  id            NUMBER,
  customer_id   NUMBER,
  COURSE  VARCHAR2(5),
  GRADE   VARCHAR(25)
);

INSERT INTO pivot_test VALUES (1, 1, 'A', 'GOOD');
INSERT INTO pivot_test VALUES (2, 1, 'B', 'GOOD');
INSERT INTO pivot_test VALUES (3, 1, 'C', 'GOOD');
INSERT INTO pivot_test VALUES (4, 2, 'A', 'BAD');
INSERT INTO pivot_test VALUES (5, 2, 'C', 'POOR');
INSERT INTO pivot_test VALUES (6, 3, 'A', 'GOOD');
INSERT INTO pivot_test VALUES (7, 3, 'B', 'POOR');
INSERT INTO pivot_test VALUES (8, 3, 'C', 'GOOD');
INSERT INTO pivot_test VALUES (9, 4, 'A', 'POOR');

select * from pivot_test;



 
                                            A                          B                                  C
 
 CUSTOMERID   Good Bad Poor     Good Bad Poor         Good Bad Poor
 
 1                              1                            1                                    1
 2                                      1                                                                              1
 3                               1                                            1                    1
4                                              1
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE