Hello All,
I'm trying to get unpivot and pivot to work and can't quite wrap my head around it.
I created a test table which contains DAY, TYPE, DB_ID. In short the backup schedule for a database instance.
Here is my SQL and output.
select b.day_abbrev, c.bck_type_abbrev
from ori_bck_schedules a
left join ori_days b on b.day_id = a.day_id
left join ori_bck_types c on c.bck_type_id = a.bck_type_id
left join ori_databases d on d.database_id = a.database_id
where a.database_id = 369;
DAY_ABBREV BCK_TYPE_ABBREV
---------- ---------------
SUN FULL
MON INCR
TUE INCR
WED INCR
THU INCR
FRI INCR
SAT FULL
I would like to unpivot this table to get 1 rows showing the day of the weekend and the type of backup? And I ultimately would like to have 1 row showing the day of the week and then just rows showing the DB_ID.
Here is what I mean:
SUN MON TUE WED
DB1 FULL FULL INCR
DB2 INCR INCR FULL
DB3 ......
The below code is not working for me.
select b.day_abbrev as "day", c.bck_type_abbrev as "type"
from ori_bck_schedules a
left join ori_days b on b.day_id = a.day_id
left join ori_bck_types c on c.bck_type_id = a.bck_type_id
left join ori_databases d on d.database_id = a.database_id
unpivot (a for day_abbrev in (b.day_abbrev as 'D',c. bck_type_abbrev as 'T'))
;
ORA-01748: only simple column names allowed here
01748. 00000 - "only simple column names allowed here"
*Cause:
*Action:
Error at Line: 45 Column: 31
Can anybody help? Thanks in advance for any assistance
Jan