22 lines
638 B
Text
22 lines
638 B
Text
create or replace table A (i integer, j integer, value float );
|
|
insert into A values
|
|
(1, 1, 1),
|
|
(1, 2, 2),
|
|
(1, 3, 3),
|
|
(2, 1, 2),
|
|
(2, 2, 5),
|
|
(2, 3, 7);
|
|
|
|
# transposition
|
|
create or replace table AT as
|
|
(select j as i, i as j, value from A);
|
|
|
|
.print The matrix-like representation of A:
|
|
create or replace table AMatrix as (pivot A on j using max(value) order by i);
|
|
from AMatrix;
|
|
|
|
.print Convert the matrix-like representation back to the (i,j,value) representation:
|
|
unpivot AMatrix on columns('^[1-9]') into name j VALUE value;
|
|
|
|
.print The matrix-like representation of "A transpose":
|
|
pivot AT on j using max(value) order by i;
|