I have a table(competency) with 150+ data which can be inserted or updated by user at anytime. I want to convert the rows of this table to columns and create another view. This view should have rows as employees where the employee table is defined separately. I tried to use PIVOT function but couldn't resolve how to define the columns as it will be dynamic.
orginal table
competency_id | competency_group | organization | position | job |
---|---|---|---|---|
ENGLISH | LANGUAGE | my_org | my_pos | my_Job |
FRENCH | LANGUAGE | my_org | my_pos | my_Job |
JAPANESE | LANGUAGE | my_org | my_pos | my_Job |
new view (expected one)
ENGLISH | FRENCH | JAPANESE |
---|---|---|
------- | ------ | -------- |
------- | ------ | -------- |
------- | ------ | -------- |
Edit when I tried it like below it worked for specified columns
select * from (
select competency_id
from competency_tab t
)
pivot
(
count(competency_id)
for competency_id in ('ENGLISH', 'GERMAN')
)
But when I tried to uses select statement like below it gives an error
select * from (
select competency_id
from competency_tab t
)
pivot
(
count(competency_id)
for competency_id in (SELECT DISTINCT competency_id FROM competency_tab)
)