1
Considering that the column Untitled2
will contain line ordering, for the same id value, here is suggestion using classic pivot:
-- código #1
SELECT id,
max(case when C1 = 1 then 1 end) as nC1,
max(case when C1 = 1 then C2 end) as nC2,
max(case when C1 = 2 then 2 end) as nC3,
max(case when C1 = 2 then C2 end) as nC4
from tabela
group by id;
In the code above C1
is the column Untitled2
and C2
is the column Untitled3
, considering the first image.
As a matter of curiosity, here’s another solution:
-- código #2
SELECT T1.id,
T1.C1 as nC1, T1.C2 as nC2,
T2.C1 as nC3, T2.C2 as nC4
from tabela as T1
left join tabela as T2 on T1.id = T2.id
where T1.C1 = 1
and (T2.id is null or T2.C1 = 2);
The untitled2 column of the first query will always have the values 1 and 2 to indicate the first and second lines?
– José Diz