Example: Using UNPIVOT with the EXCLUDE NULLS Clause - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

In this example, there are no rows with nulls in either the sales or cogs columns, and the rows are excluded in the output when using EXCLUDE NULLS clause. This is the default option.

SELECT *
FROM star1p UNPIVOT EXCLUDE NULLS (sales, cogs)  FOR  yr_qtr IN
((Q101Sales, Q101Cogs) AS 'Q101', (Q201Sales, Q201Cogs) AS 'Q201', (Q301Sales, Q301Cogs) AS 'Q301') Tmp;
country  state     yr_qtr        sales         cogs
-------  ------   --------   ------------    -------
Canada      ON     Q201           10            0
Canada      ON     Q301           10            0
USA         NY     Q101           45           25
USA         CA     Q101           30           15
USA         CA     Q201           50           20