Example: Table Source Using the WITH Clause - Advanced SQL Engine - Teradata Database

SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-30
dita:mapPath
tpt1555966086716.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata Vantageā„¢

The following is an example of a table using the WITH clause as a source to the pivot query.

SELECT *
FROM (with temp
as (select * from s1) select * from temp)dt PIVOT (SUM(sales) FOR mon IN ('Jan','Feb', 'Mar'))tmp;

 *** Query completed. 3 rows found. 4 columns returned.
 *** Total elapsed time was 1 second.
         yr          Jan          Feb          Mar
      -----        ------       ------      -------
       2001          100          110          120
       2002          150          200          250
       2003          300          310            ?