Neoview SQL Reference Manual (R2.5)

The table MYTABLE has columns A, B, C, D, E, and F with related data. The columns A, B, and
C are type INTEGER, and columns D, E, and F are type CHAR.
FEDCBA
f1e1d1100101
f2e2d2200202
Suppose that MYTABLE has only the first three columns: A, B, and C. The result of the
TRANSPOSE clause has three times as many rows (because there are three items in the
transpose item list) as there are rows in MYTABLE:
SELECT * FROM mytable
TRANSPOSE A, B, C AS VALCOL
KEY BY KEYCOL;
The result table of the TRANSPOSE query is:
VALCOLKEYCOLFEDCBA
11f1e1d1100101
102f1e1d1100101
1003f1e1d1100101
21f2e2d2200202
202f2e2d2200202
2003f2e2d2200202
This query shows that the items in the transpose item list can be any valid scalar expressions:
SELECT KEYCOL, VALCOL, A, B, C FROM mytable
TRANSPOSE A + B, C + 3, 6 AS VALCOL
KEY BY KEYCOL;
The result table of the TRANSPOSE query is:
CBAVALCOLKEYCOL
100101111
1001011032
10010163
200202221
2002022032
20020263
This query shows how the TRANSPOSE clause can be used with a GROUP BY clause. This
query is typical of queries used to obtain cross-table information, where A, B, and C are the
independent variables, and D is the dependent variable.
SELECT KEYCOL, VALCOL, D, COUNT(*) FROM mytable
TRANSPOSE A, B, C AS VALCOL
KEY BY KEYCOL
GROUP BY KEYCOL, VALCOL, D;
332 SQL Clauses