Skip to content
Learn Netverks

Lesson

Step 24/36 67% through track

window-functions-intro

Window functions

Last reviewed May 28, 2026 Content v20260528
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~2 min
Level
advanced

This lesson

An orientation to the SQL track—relational concepts, query patterns, and how to practice until the SQL sandbox lab ships.

You need a clear map of the SQL track so tables, keys, JOINs, and aggregates do not feel like magic.

You will apply Window functions in contexts like: Rankings, funnels, and warehouse SQL in Snowflake, BigQuery, or Postgres analytics.

Copy SQL from each lesson into SQLite (sqlite3), DB Fiddle, or local Postgres—read result grids and row counts. The in-browser SQL lab (sql_sandbox) will run queries when the runner ships; until then, local clients are the practice path. Also read the interview prep blocks.

After basic programming literacy—before ORM-heavy frameworks assume you can read the SQL they generate.

Window functions compute values across related rows without collapsing the result set like GROUP BY. Rankings, running totals, and row-over-row comparisons are typical uses in analytics and reporting.

ROW_NUMBER and RANK

SELECT customer_id,
       total,
       ordered_at,
       ROW_NUMBER() OVER (
         PARTITION BY customer_id
         ORDER BY ordered_at DESC
       ) AS rn
FROM orders;

Practice: Advanced features vary by engine—SQLite 3.25+ supports window functions; test your version with a simple query.

Running sum

SELECT ordered_at,
       total,
       SUM(total) OVER (
         ORDER BY ordered_at
         ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
       ) AS running_total
FROM orders;

OVER defines the window; PARTITION BY resets per group.

Window vs GROUP BY

GROUP BY returns one row per group; window functions keep detail rows while adding aggregate columns—common in Data Science feature engineering SQL.

Important interview questions and answers

  1. Q: PARTITION BY does what?
    A: Splits rows into groups over which the window function runs separately.
  2. Q: ROW_NUMBER vs RANK?
    A: ROW_NUMBER is unique per row; RANK leaves gaps after ties.

Self-check

  1. Which clause defines the window for a window function?
  2. When choose window functions over GROUP BY?

Tip: Check SQLite version (SELECT sqlite_version();)—window functions need 3.25+.

Interview prep

Window vs GROUP BY?

Window keeps detail rows; GROUP BY collapses to one row per group.

PARTITION BY?

Splits rows into groups for the window calculation.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • PARTITION BY?
  • ROW_NUMBER vs RANK?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump