MDIFF Function Examples | Teradata Vantage - 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)

Display the difference between each quarter and the same quarter sales for last year for product code 10.

   SELECT year_of_calendar, quarter_of_calendar,
   MDIFF(sumPrice, 4, year_of_calendar, quarter_of_calendar)
   FROM (SELECT a2.year_of_calendar,
   a2.quarter_of_calendar, SUM(a2.Price) AS sumPrice
   FROM Sales a1, SYS_CALENDAR.Calendar a2
   WHERE a1.itemID=10 and a1.calendar_date=a2.calendar_date
   GROUP BY a2.year_of_calendar, a2.quarter_of_calendar) AS T1
   ORDER BY year_of_calendar, quarter_of_year;