17.10 - Example - Advanced SQL Engine - Teradata Database

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

Advanced SQL Engine
Teradata Database
Release Number
Release Date
July 2021
Content Type
Programming Reference
Publication ID
English (United States)

Provide a running total for sales of each item in store 5 in January and generate output that is ready to export into a graphing program.

   SELECT Item, SalesDate, CSUM(Revenue,Item,SalesDate) AS CumulativeSales 
   (SELECT Item, SalesDate, SUM(Sales) AS Revenue
   FROM DailySales
   WHERE StoreId=5 AND SalesDate BETWEEN 
   '1/1/1999' AND '1/31/1999'
   GROUP BY Item, SalesDate) AS ItemSales
   ORDER BY SalesDate;

The result might like something like the following table.

Item SalesDate CumulativeSales
InstaWoof dog food 01/01/1999 972.99
InstaWoof dog food 01/02/1999 2361.99
InstaWoof dog food 01/03/1999 5110.97
InstaWoof dog food 01/04/1999 7793.91