16.20 - Example: Using UNPIVOT for a Unique Year Value - Teradata Vantage NewSQL Engine

Teradata Vantage™ SQL Functions, Expressions, and Predicates

prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1145-162K

This example shows only one unique value of year, so the unpivot is straightforward.

SELECT *
FROM star1p UNPIVOT (Q1sales, Q2sales, Q3sales, Q1cogs, Q2cogs, Q3cogs) FOR
yr IN ((Q101Sales, Q201Sales, Q301Sales, Q101Cogs, Q201Cogs, Q301Cogs) AS
‘2001’) Tmp;

country  state  yr     Q1sales  Q2sales  Q3sales  Q1cogs  Q2cogs  Q3cogs
-------  -----  ----  --------  -------  -------  ------  ------  ------
Canada   ON     2001    ?         10        ?      ?        0       ?
Canada   BC     2001    ?          ?       10      ?        ?       0
USA      NY     2001    45         ?        ?      25       ?       ?
USA      CA     2001    30        50        ?      15       20