I have below table.
If a new indicator is added, it should be entered in the Auto Convert column
(id int,indicator text,value int
);
INSERT INTO _test (id,indicator,value) values
(1,'A1',10),(1,'A2',12),(2,'B1',20),(2,'B2',22);
--using the column name.
select id,
max(CASE WHEN indicator = 'A1' THEN value END ) as "A1",
max(CASE WHEN indicator = 'A2' THEN value END ) as "A2",
max(CASE WHEN indicator = 'B1' THEN value END ) as "B1",
max(CASE WHEN indicator = 'B2' THEN value END ) as "B2"
from _test
group by id order by id;
--After new indicator is added here.
INSERT INTO _test (id,indicator,value) values
(3,'C1',30),(3,'C2',31);
How will the new indicator update in the new column.
returns should be below
id | A1 | A2 | B1 | B2 | C1 | C2 |
---|---|---|---|---|---|---|
1 | 10 | 12 | ||||
2 | 20 | 22 | ||||
3 | 30 | 31 |