Example

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

brand
Software
Teradata Vantage
prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1145-162K

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;