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)

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;