Example - 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ā„¢

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 
   FROM 
   (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