Example: Using UNPIVOT for a Unique Year Value - Analytics Database - Teradata Vantage

SQL Functions, Expressions, and Predicates

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-01-12
dita:mapPath
obm1628111499646.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
kby1472250656485
lifecycle
latest
Product Category
Teradata Vantage™

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;

Result:

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