internalsGet Pro

Module 02 · Lesson 3 of 12Pro

Window functions: running totals and rankings

Level
Intermediate
Topic
SQL for data engineering
Reading time
17 min

When you finish this page you can

  1. Add running totals, changes from the day before and rankings to every row with window functions, instead of folding the rows with GROUP BY.
  2. Choose between ROW_NUMBER, RANK and DENSE_RANK by what a tie should mean for the people who read the result.
  3. Predict which rows a window frame adds up, and write ROWS or RANGE on purpose so ties can’t change a number.
  4. Keep running totals right in a nightly pipeline when past days still change.
  1. Design: a first analytics pipeline for an online store30 min
  2. NULLs and messy values in SQL16 min

Monday’s number needs the month beside it

It’s 07:00 on Tuesday, 10 November. is an online store in India. Every night, Meera’s pipeline copies the day’s orders from the store’s PostgreSQL read replica into and builds daily_revenue, one row per day. Daniel, who leads finance reporting, reads it every morning. Monday shows ₹6.5 crore.

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan