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)

The following example groups all items into deciles by profitability.

   SELECT Item, Profit, QUANTILE(10, Profit) AS Decile
   FROM
      (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