MAVG Function Examples | Teradata Vantage - 17.10 - Example - Advanced SQL Engine - Teradata Database

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

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1145-171K
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);