Tabellab
Read first

The SQL

SELECT product, revenue
FROM products
ORDER BY revenue DESC
LIMIT 3;

-- rank of every row (a window function)
SELECT product, RANK() OVER (ORDER BY revenue DESC) AS revenue_rank
FROM products;

SELECT product FROM products
ORDER BY units ASC
LIMIT 1;

The spreadsheet equivalent

  • RANK() OVER (ORDER BY revenue DESC) → =RANK.EQ(E2,$E$2:$E$13,0)
  • ORDER BY revenue DESC LIMIT 3 → LARGE(E2:E13, 1 … 3) + INDEX/MATCH for the name
  • ORDER BY units ASC LIMIT 1 → MIN(D2:D13) + INDEX/MATCH
  • SQL Server writes SELECT TOP 3 … instead of LIMIT 3; the idea is the same
Loading the spreadsheet…