16.20 - Example - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2020-03-25
dita:mapPath
xzf1512079057909.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.ditaval
dita:id
kby1472250656485

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