Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,7 @@
# Given two tables, A and B, representing two matrices in (i,j,value) format, the product
# can be computed as follows, with the result being in the same format.
SELECT A.i, B.j,
SUM(A.value * B.value) AS value
FROM A INNER JOIN B
ON A.j = B.i
GROUP BY A.i, B.j;

View file

@ -0,0 +1,16 @@
# The following SQL statement will convert a table A representing an m by n matrix
# in (i,j,value) format to a table with m rows and (n+1) columns, the first being the row id:
pivot A on j using max(value) order by i;
# To exclude the row id column:
select columns(* exclude (i)) from (pivot A on j using max(value)) order by i;
# To ensure the columns are presented in their natural order,
# the above 'select' statement may need to be adjusted.
# If n < 10, the following would suffice:
select columns(* exclude (i)) from (pivot A on j using max(value)) order by i;
# For 10 to 99 columns:
select columns('^[1-9]$'), columns('^[1-9][0-9]') from (pivot A on j using max(value)) order by i;
# If there are more than 99 columns, the above can be extended in the obvious way.

View file

@ -0,0 +1,39 @@
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);
create or replace table B (i integer, j integer, value float );
insert into B values
(1, 1, 2),
(1, 2, 4),
(1, 3, 8),
(2, 1, 1),
(2, 2, 5),
(2, 3, -10),
(3, 1, 3),
(3, 2, 6),
(3, 3, 9);
.print Display A in a matrix format including the row id
pivot A on j using max(value) order by i;
.print Display B likewise
pivot B on j using max(value) order by i;
. print Compute C = A * B
CREATE OR REPLACE table C as
SELECT A.i, B.j,
SUM(A.value * B.value) AS value
FROM A INNER JOIN B
ON A.j = B.i
GROUP BY A.i, B.j;
.print Display C in matrix format excluding the row id
select columns(* exclude (i))
from (pivot C on j using max(value))
order by i;