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)

The following example groups all items into deciles by profitability.

   SELECT Item, Profit, QUANTILE(10, Profit) AS Decile
      (SELECT Item, Sum(Sales) — (Count(Sales) * ItemCost) AS Profit
      FROM DailySales, Items
      WHERE DailySales.Item = Items.Item
      GROUP BY Item) AS Item;

The result might look like the following table.

Item Profit Decile
High Tops 97112 9
Low Tops 74699 7
Running 69712 6
Casual 28912 3
Xtrain 100129 9