Example: Sorting and Reporting Items by Category and Descending Revenue Rank Using RANK (Teradata) - Teradata VantageCloud Lake

Lake - Working with SQL

Deployment
VantageCloud
Edition
Lake
Product
Teradata VantageCloud Lake
Release Number
Published
February 2025
ft:locale
en-US
ft:lastEdition
2025-11-21
dita:mapPath
jbe1714339405530.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
jbe1714339405530

Sort items by category and report items in order of descending revenue rank.

   SELECT Category, Item, Revenue, RANK(Revenue) AS ItemRank
   FROM ItemCategory,
      (SELECT Item, SUM(sales) AS Revenue
      FROM DailySales
      GROUP BY Item) AS ItemSales
   WHERE ItemCategory.Item = ItemSales.Item
   ORDER BY Category, ItemRank DESC;

The result may look like the following table.

Category Item Revenue ItemRank
Hot Cereal Regular Oatmeal 39112.00 4
Hot Cereal Instant Oatmeal 44918.00 3
Hot Cereal Regular COW 59813.00 2
Hot Cereal Instant COW 75411.00 1