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
Release Date
March 2019
Content Type
Programming Reference
Publication ID
B035-1145-162K
Language
English (United States)

Compute the 7-day moving average of sales for product code 10 for each day in the month of October, 1996.

   SELECT cdate, itemID, MAVG(sumPrice, 7, date)
   FROM (SELECT a1.calendar_date, a1.itemID,
   SUM(a1.price)
   FROM Sales a1
   WHERE a1.itemID=10 AND a1.calendar_date
   BETWEEN 96-10-01 AND 96-10-31
   GROUP BY a1.calendar_date, a1.itemID) AS T1(cdate,
   itemID, sumPrice);