Example: Table Source Using the WITH Clause

Teradata Vantageā„¢ SQL Functions, Expressions, and Predicates

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

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            ?