元table
—————-
id,col
—————-
1,a
1,b
—————-
これを
—————-
id,col1,col2
1,a,b
—————-
にする
select
a.id,
a.col as col1,
b.col as col2
from
ta a
inner join
ta b
on a.id = b.id
where
a.col = “a”
and
b.col = “b”
ちなみに、横→縦はUNION使う
https://qiita.com/k24d/items/79bc4828c918dfeeac34
Unpivotの
SELECT uid, 'c1' AS key, c1 AS value FROM htable
UNION ALL
SELECT uid, 'c2' AS key, c2 AS value FROM htable
UNION ALL
SELECT uid, 'c3' AS key, c3 AS value FROM htable
;
uid key value
— — —–
101 c1 11
102 c1 21
101 c2 12
102 c2 22
101 c3 13
102 c3 23