1
select * from (select REGS_CRSE_TITLE as CRSE_TITLE, REGS_BILL_HR as BILL_HOURS, FCR_TO_DATE, FCR_TUIT_REFUND
from REGS, FCR
where REGS_ID = 123456
and REGS_CODE = FCR_CODE
and FCR_TERM_CODE = 2019
and FCR_RSTS_CODE in ('CD','CW')
order by REGS_CRSE_TITLE
)
pivot
(
max (FCR_TO_DATE)
for FCR_TUIT_REFUND IN (100, 50)
);

Which produces a result similar to the following:

CRSE_TITLE                 BILL_HOURS             100         50
English II                     3               28-Aug-19    9-Sep-19
Sculpture 1                    3               28-Aug-19    9-Sep-19
Intro to Business              3               28-Aug-19    9-Sep-19
Graphic Design                 3               28-Aug-19    9-Sep-19
Senior Project               0.5               28-Aug-19    9-Sep-19
Web Application Dev            3               28-Aug-19    9-Sep-19

I need to rename the columns that get created by the pivot to something else. So the 100 and 50 column headers would be renamed to something more meaningful. I can't seem to do it with a simple 'AS' like the first two columns. Also the 'Order By' does not seem to work in this context either, but that is not as important to me as getting the columns renamed. Any help would be greatly appreciated!

Tyler
  • 13
  • 3

1 Answers1

1

You could use AS and ORDER BY should be the last clause:

...
pivot
(
max (FCR_TO_DATE)
for FCR_TUIT_REFUND IN (100 AS col1, 50 AS col2)
)
order by CRSE_TITLE 
;
Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275