Window Frames: Running Totals and Moving Averages With ROWS, RANGE and GROUPS
How the frame clause decides which rows a window aggregate sees: running and reverse totals, cumulative percentages, trailing and centred moving averages, ROWS versus RANGE versus GROUPS and how they treat gaps and ties, the default frame, EXCLUDE, and support in each database.
kvi5hnuCode Sprout team member13 min readOn this page
Article 26 showed that ORDER BY inside OVER turns SUM into a running total. That's one example of a more general idea. Within each partition, a window aggregate looks at a frame: a range of rows around the current row. With an ORDER BY, the default frame is "from the first row up to the current row and its peers". Without one, it's the whole partition. The frame clause lets you choose any other range: the last three rows, the current row and its neighbours, everything after the current row, or all the rows within seven days.
With frames, one query can produce running totals, moving averages, rolling maximums and many other calculations that would otherwise need self-joins. This article explains the frame clause, its three modes, ROWS, RANGE and GROUPS, and how they behave when the data has gaps or ties.
The examples use a small table of daily takings for a market stall, from 1 to 8 March. The stall didn't trade on 4 March, so there's no row for that day:
CREATE TABLE daily_sales (
day DATE PRIMARY KEY,
amount DECIMAL(8, 2) NOT NULL
);
-- 1 Mar 120.00, 2 Mar 80.00, 3 Mar 150.00, 5 Mar 60.00,
-- 6 Mar 200.00, 7 Mar 90.00, 8 Mar 110.00
The frame clause
A frame is written after the window's ORDER BY:
function(...) OVER (
PARTITION BY ...
ORDER BY ...
{ ROWS | RANGE | GROUPS } BETWEEN frame_start AND frame_end
)
Each boundary is one of:
| Boundary | Meaning |
|---|---|
UNBOUNDED PRECEDING | the first row of the partition |
n PRECEDING | n rows (or n units, or n groups) before the current row |
CURRENT ROW | the current row (with RANGE and GROUPS: its peers too) |
n FOLLOWING | n rows (or units, or groups) after the current row |
UNBOUNDED FOLLOWING | the last row of the partition |
The start must not come after the end. If you give only a start, as in ROWS 2 PRECEDING, the end is CURRENT ROW.
Frames apply to aggregate functions used as window functions, and to FIRST_VALUE, LAST_VALUE and NTH_VALUE (article 29). Ranking functions and LAG/LEAD ignore the frame: they always work on the whole partition.
Cumulative calculations
-- Daily takings of a market stall; no trading on 4 March
CREATE TABLE daily_sales (
day DATE PRIMARY KEY,
amount DECIMAL(8, 2) NOT NULL
);
INSERT INTO daily_sales VALUES
(DATE '2026-03-01', 120.00),
(DATE '2026-03-02', 80.00),
(DATE '2026-03-03', 150.00),
(DATE '2026-03-05', 60.00),
(DATE '2026-03-06', 200.00),
(DATE '2026-03-07', 90.00),
(DATE '2026-03-08', 110.00);
-- Cumulative calculations: from the first row to the current one, and onwards
SELECT day,
amount,
SUM(amount) OVER (ORDER BY day
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_total,
ROUND(100.0 * SUM(amount) OVER (ORDER BY day
ROWS UNBOUNDED PRECEDING)
/ SUM(amount) OVER (), 1) AS cumulative_pct,
SUM(amount) OVER (ORDER BY day
ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) AS still_to_come,
MAX(amount) OVER (ORDER BY day
ROWS UNBOUNDED PRECEDING) AS best_day_so_far
FROM daily_sales
ORDER BY day;
day | amount | running_total | cumulative_pct | still_to_come | best_day_so_far
------------+--------+---------------+----------------+---------------+-----------------
2026-03-01 | 120.00 | 120.00 | 14.8 | 810.00 | 120.00
2026-03-02 | 80.00 | 200.00 | 24.7 | 690.00 | 120.00
2026-03-03 | 150.00 | 350.00 | 43.2 | 610.00 | 150.00
2026-03-05 | 60.00 | 410.00 | 50.6 | 460.00 | 150.00
2026-03-06 | 200.00 | 610.00 | 75.3 | 400.00 | 200.00
2026-03-07 | 90.00 | 700.00 | 86.4 | 200.00 | 200.00
2026-03-08 | 110.00 | 810.00 | 100.0 | 110.00 | 200.00
(7 rows)
running_totaluses the frame from the first row to the current row. It's the same as the default frame here, but written out, and withROWS, which matters when there are ties (see below).cumulative_pctdivides the running total by the grand total fromOVER (), giving the percentage of the period's takings reached by each day. By 5 March, the stall had taken half its total.ROWS UNBOUNDED PRECEDINGis the short form ofROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.still_to_comereverses the frame: from the current row to the end. It's a reverse running total, such as the amount left on a payment plan.best_day_so_farusesMAXwith a cumulative frame: the highest takings up to and including each day. Any aggregate works with any frame.
Moving averages
A moving average smooths out daily ups and downs by averaging each value with its neighbours. It's the most common use of a sliding frame:
-- Daily takings of a market stall; no trading on 4 March
CREATE TABLE daily_sales (
day DATE PRIMARY KEY,
amount DECIMAL(8, 2) NOT NULL
);
INSERT INTO daily_sales VALUES
(DATE '2026-03-01', 120.00),
(DATE '2026-03-02', 80.00),
(DATE '2026-03-03', 150.00),
(DATE '2026-03-05', 60.00),
(DATE '2026-03-06', 200.00),
(DATE '2026-03-07', 90.00),
(DATE '2026-03-08', 110.00);
-- Moving averages: trailing 3 rows, and centred on the current row
SELECT day,
amount,
ROUND(AVG(amount) OVER (ORDER BY day
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW), 2) AS trailing_avg,
COUNT(*) OVER (ORDER BY day
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS rows_used,
ROUND(AVG(amount) OVER (ORDER BY day
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING), 2) AS centred_avg
FROM daily_sales
ORDER BY day;
day | amount | trailing_avg | rows_used | centred_avg
------------+--------+--------------+-----------+-------------
2026-03-01 | 120.00 | 120.00 | 1 | 100.00
2026-03-02 | 80.00 | 100.00 | 2 | 116.67
2026-03-03 | 150.00 | 116.67 | 3 | 96.67
2026-03-05 | 60.00 | 96.67 | 3 | 136.67
2026-03-06 | 200.00 | 136.67 | 3 | 116.67
2026-03-07 | 90.00 | 116.67 | 3 | 133.33
2026-03-08 | 110.00 | 133.33 | 3 | 100.00
(7 rows)
trailing_avgaverages the current row and the two before it: a 3-row trailing average. For 3 March, that's (120 + 80 + 150) / 3 = 116.67.rows_usedshows a detail that's easy to miss: at the start of the data, the frame is smaller, because there are no earlier rows. The first day's "3-row average" is just that day's amount, and the second day's averages two rows. A report might hide those first values, or show them only whenrows_usedis 3.centred_avguses one row before and one after:ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING. It lines up with the middle of the period it averages, which suits charts, but the value for the latest day can't be final until the next day arrives.
ROWS versus RANGE: gaps in the data
ROWS counts physical rows. RANGE measures distance in the value of the ORDER BY column. They give the same results when the data has one row per day with no gaps. Here, 4 March is missing:
-- Daily takings of a market stall; no trading on 4 March
CREATE TABLE daily_sales (
day DATE PRIMARY KEY,
amount DECIMAL(8, 2) NOT NULL
);
INSERT INTO daily_sales VALUES
(DATE '2026-03-01', 120.00),
(DATE '2026-03-02', 80.00),
(DATE '2026-03-03', 150.00),
(DATE '2026-03-05', 60.00),
(DATE '2026-03-06', 200.00),
(DATE '2026-03-07', 90.00),
(DATE '2026-03-08', 110.00);
-- ROWS counts rows; RANGE measures distance in the ORDER BY value (here, days)
SELECT day,
amount,
ROUND(AVG(amount) OVER (ORDER BY day
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW), 2) AS avg_3_rows,
COUNT(*) OVER (ORDER BY day
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS n_rows,
ROUND(AVG(amount) OVER (ORDER BY day
RANGE BETWEEN INTERVAL '2 days' PRECEDING
AND CURRENT ROW), 2) AS avg_3_days,
COUNT(*) OVER (ORDER BY day
RANGE BETWEEN INTERVAL '2 days' PRECEDING
AND CURRENT ROW) AS n_days
FROM daily_sales
ORDER BY day;
day | amount | avg_3_rows | n_rows | avg_3_days | n_days
------------+--------+------------+--------+------------+--------
2026-03-01 | 120.00 | 120.00 | 1 | 120.00 | 1
2026-03-02 | 80.00 | 100.00 | 2 | 100.00 | 2
2026-03-03 | 150.00 | 116.67 | 3 | 116.67 | 3
2026-03-05 | 60.00 | 96.67 | 3 | 105.00 | 2
2026-03-06 | 200.00 | 136.67 | 3 | 130.00 | 2
2026-03-07 | 90.00 | 116.67 | 3 | 116.67 | 3
2026-03-08 | 110.00 | 133.33 | 3 | 133.33 | 3
(7 rows)

For 5 March:
ROWS BETWEEN 2 PRECEDING AND CURRENT ROWtakes the two rows before it, 2 and 3 March, so the average covers four calendar days.RANGE BETWEEN INTERVAL '2 days' PRECEDING AND CURRENT ROWtakes the rows whose date is within two days of 5 March, from 3 to 5 March. There's no row for 4 March, so it averages 3 and 5 March only.
Which is right depends on what "the last 3 days" means for your data. If a missing day means "no sales", RANGE gives a true calendar window, though it averages only the days present. To treat missing days as zero, fill them in first with a date series (article 41). If rows are measurements taken whenever possible, ROWS gives "the last 3 readings".
RANGE with an offset needs a single ORDER BY column whose type supports subtraction: numbers, dates and timestamps. The offset must be of a compatible type, such as an INTERVAL for dates.
Peers: ROWS, RANGE and GROUPS with ties
The three modes also differ in how they treat peers, rows that tie on the ORDER BY value:
CREATE TABLE products (
product_id INTEGER PRIMARY KEY,
name VARCHAR(40) NOT NULL,
category VARCHAR(20) NOT NULL,
brand VARCHAR(20),
price DECIMAL(8, 2) NOT NULL,
stock INTEGER NOT NULL,
weight_g INTEGER
);
INSERT INTO products VALUES
(1, 'Ridge 2 tent', 'tents', 'Alpina', 249.99, 12, 2100),
(2, 'Summit 4 tent', 'tents', 'Alpina', 489.00, 3, 4300),
(3, 'Glow head torch', 'lighting', 'Lumen', 34.50, 40, 90),
(4, 'Basecamp lantern', 'lighting', NULL, 27.00, 15, NULL),
(5, 'Trail 30 backpack', 'packs', 'Kestrel', 89.95, 22, 1150),
(6, 'Day 18 backpack', 'packs', 'Kestrel', 54.00, 0, 640),
(7, 'Merino socks', 'clothing', 'Woolly', 16.00, 75, 80);
-- Peers: rows with the same ORDER BY value (here, the same category)
SELECT category,
price,
SUM(price) OVER (ORDER BY category ROWS UNBOUNDED PRECEDING) AS by_rows,
SUM(price) OVER (ORDER BY category RANGE UNBOUNDED PRECEDING) AS by_range,
SUM(price) OVER (ORDER BY category GROUPS BETWEEN 1 PRECEDING
AND CURRENT ROW) AS this_and_prev_group
FROM products
ORDER BY category, price;
category | price | by_rows | by_range | this_and_prev_group
----------+--------+---------+----------+---------------------
clothing | 16.00 | 16.00 | 16.00 | 16.00
lighting | 27.00 | 77.50 | 77.50 | 77.50
lighting | 34.50 | 50.50 | 77.50 | 77.50
packs | 54.00 | 221.45 | 221.45 | 205.45
packs | 89.95 | 167.45 | 221.45 | 205.45
tents | 249.99 | 471.44 | 960.44 | 882.94
tents | 489.00 | 960.44 | 960.44 | 882.94
(7 rows)
The window is ordered by category only, so the two products in each category are peers.
ROWStreats each row separately. The running sum steps through the tied rows one at a time, but the order among the peers is arbitrary: in the result, the 34.50 head torch happened to be added before the 27.00 lantern. Run it elsewhere and the intermediate values could differ.RANGEwithCURRENT ROWincludes all the current row's peers. Both lighting rows get 77.50, the total up to the end of lighting. This is the default frame when the window has anORDER BY.GROUPScounts peer groups rather than rows or values.GROUPS BETWEEN 1 PRECEDING AND CURRENT ROWcovers the current category and the previous one. For the packs rows, that's lighting (61.50) plus packs (143.95) = 205.45.
The lessons:
- If the
ORDER BYin a window can tie, aROWSframe gives arbitrary results unless you add a tie-breaker that makes the order unique. RANGEandGROUPSgive the same value to all peers, which is deterministic.- Use
GROUPSfor "the last N distinct dates", when several rows can share a date:GROUPS BETWEEN 6 PRECEDING AND CURRENT ROWcovers seven distinct dates however many rows each has.
The default frame
When you write no frame clause, the frame depends on whether the window has an ORDER BY:
| Window | Default frame |
|---|---|
no ORDER BY | the whole partition |
with ORDER BY | RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: up to the current row and its peers |
That's why SUM(x) OVER (PARTITION BY g) gives the group total, while SUM(x) OVER (PARTITION BY g ORDER BY d) gives a running total. It's also the reason for a famous surprise with LAST_VALUE, which, with the default frame, returns the current row's value rather than the partition's last value. Article 29 explains it.
Writing the frame explicitly whenever you add ORDER BY to an aggregate's window removes any doubt, and with ROWS it's often faster.
EXCLUDE
The frame clause can end with EXCLUDE, which removes rows from the frame:
-- Daily takings of a market stall; no trading on 4 March
CREATE TABLE daily_sales (
day DATE PRIMARY KEY,
amount DECIMAL(8, 2) NOT NULL
);
INSERT INTO daily_sales VALUES
(DATE '2026-03-01', 120.00),
(DATE '2026-03-02', 80.00),
(DATE '2026-03-03', 150.00),
(DATE '2026-03-05', 60.00),
(DATE '2026-03-06', 200.00),
(DATE '2026-03-07', 90.00),
(DATE '2026-03-08', 110.00);
-- EXCLUDE: the neighbours' total, leaving out the current row itself
SELECT day,
amount,
SUM(amount) OVER (ORDER BY day
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
EXCLUDE CURRENT ROW) AS neighbours_total
FROM daily_sales
ORDER BY day;
-- Frame errors
SELECT SUM(amount) OVER (ORDER BY day ROWS BETWEEN CURRENT ROW AND 1 PRECEDING)
FROM daily_sales;
SELECT SUM(amount) OVER (ORDER BY day, amount
RANGE BETWEEN 1 PRECEDING AND CURRENT ROW)
FROM daily_sales;
day | amount | neighbours_total
------------+--------+------------------
2026-03-01 | 120.00 | 80.00
2026-03-02 | 80.00 | 270.00
2026-03-03 | 150.00 | 140.00
2026-03-05 | 60.00 | 350.00
2026-03-06 | 200.00 | 150.00
2026-03-07 | 90.00 | 310.00
2026-03-08 | 110.00 | 90.00
(7 rows)
psql:/workspace/solution.sql:26: ERROR: frame starting from current row cannot have preceding rows
LINE 1: ...) OVER (ORDER BY day ROWS BETWEEN CURRENT ROW AND 1 PRECEDIN...
^
psql:/workspace/solution.sql:30: ERROR: RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column
LINE 1: SELECT SUM(amount) OVER (ORDER BY day, amount
^
EXCLUDE CURRENT ROW gives the total of the neighbours without the row itself, useful for comparing a value with its surroundings, as in "was this day unusually high compared with the days around it?". The other options are EXCLUDE GROUP, which removes the current row and its peers, EXCLUDE TIES, which removes the peers but keeps the current row, and EXCLUDE NO OTHERS, the default.
The two errors show common mistakes. A frame can't end before it starts, so CURRENT ROW AND 1 PRECEDING is rejected. And RANGE with an offset needs exactly one ORDER BY column, because the distance is measured in that column's value.
Support in each database
| Feature | PostgreSQL | MySQL 8 | SQL Server | Oracle | SQLite |
|---|---|---|---|---|---|
ROWS with offsets | yes | yes | yes (2012+) | yes | yes (3.25+) |
RANGE with offsets | yes (11+) | yes | no, only UNBOUNDED and CURRENT ROW | yes | yes (3.28+) |
GROUPS | yes (11+) | no | no | yes (21c+) | yes (3.28+) |
EXCLUDE | yes (11+) | no | no | yes (21c+) | yes (3.28+) |
Syntax details differ too. MySQL writes date offsets as RANGE BETWEEN INTERVAL 2 DAY PRECEDING AND CURRENT ROW. Oracle uses RANGE BETWEEN INTERVAL '2' DAY PRECEDING AND CURRENT ROW, or a plain number of days for DATE columns. In SQL Server, where RANGE has no offsets, a calendar-based moving window needs a filled-in date series with ROWS, or a correlated subquery.
Performance
A sliding frame doesn't recompute each window from scratch: databases add the row that enters the frame and remove the row that leaves it, for aggregates where that's possible, such as SUM, COUNT and AVG. MIN and MAX over a sliding frame are harder and can be slower on large frames.
In SQL Server, the default RANGE frame uses a slower on-disk worktable, while ROWS frames are processed in memory, so writing ROWS UNBOUNDED PRECEDING explicitly can speed up running totals considerably there. As in every window query, an index that matches PARTITION BY and ORDER BY can save the database a sort.
Running products
Some calculations multiply rather than add: compounding monthly growth rates, or chaining probabilities. There's no standard PRODUCT aggregate, but logarithms turn multiplication into addition, so EXP(SUM(LN(x))) multiplies the values, and it works as a window function too:
-- Monthly growth rates, compounded into a running product
CREATE TABLE growth (month DATE PRIMARY KEY, rate NUMERIC(5, 3));
INSERT INTO growth VALUES
(DATE '2026-01-01', 1.100), -- +10%
(DATE '2026-02-01', 0.950), -- -5%
(DATE '2026-03-01', 1.200), -- +20%
(DATE '2026-04-01', 1.050); -- +5%
-- There's no PRODUCT aggregate in PostgreSQL, but exp(sum(ln(x))) multiplies the values
SELECT month, rate,
ROUND(EXP(SUM(LN(rate)) OVER (ORDER BY month)), 4) AS cumulative_growth
FROM growth
ORDER BY month;
month | rate | cumulative_growth
------------+-------+-------------------
2026-01-01 | 1.100 | 1.1000
2026-02-01 | 0.950 | 1.0450
2026-03-01 | 1.200 | 1.2540
2026-04-01 | 1.050 | 1.3167
(4 rows)
After four months, growth of 10%, -5%, 20% and 5% compounds to 1.3167, a total increase of 31.67%. The logarithm trick needs care: LN fails for zero or negative values, so handle them separately, for example by returning 0 when any value is 0 (CASE WHEN MIN(x) = 0 THEN 0 ...) and tracking the sign with a count of negative values. SQL Server 2025 added a real PRODUCT() aggregate.
What's current
- Oracle 21c added
GROUPSframes andEXCLUDE, bringing Oracle in line with PostgreSQL and SQLite. - PostgreSQL 11 (2018) completed its support for the standard frame clause with
RANGEoffsets,GROUPSandEXCLUDE. - MySQL and SQL Server still don't support
GROUPSorEXCLUDE, and SQL Server still has no offsets inRANGEframes.
Common questions
What's the difference between ROWS and RANGE?
ROWS counts physical rows before and after the current row. RANGE selects rows by their ORDER BY value, so gaps in the data shrink the frame and ties are always included together.
What frame do I get if I don't write one?
The whole partition without ORDER BY, and RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW with ORDER BY.
Why is my moving average wrong for the first rows?
The frame is smaller at the start of the partition because there are fewer earlier rows. Count the rows in the frame with COUNT(*) over the same window and ignore or flag incomplete windows.
How do I compute a 7-day moving average when some days are missing?
Either use RANGE BETWEEN INTERVAL '6 days' PRECEDING AND CURRENT ROW, which averages the days present, or generate every date, left-join the data and use ROWS BETWEEN 6 PRECEDING AND CURRENT ROW with missing days as 0.
Do frames affect ROW_NUMBER or LAG?
No. Ranking functions and LAG/LEAD ignore the frame.
Can I use a frame without ORDER BY?
ROWS frames with offsets need an ordering to be meaningful, and RANGE with offsets requires one ORDER BY column. Without ORDER BY, all rows are peers.
What's GROUPS for?
For frames measured in distinct values, such as "the last 3 distinct dates", when several rows can share a value.
Summary
- The frame clause chooses which rows of the partition a window aggregate sees, relative to the current row.
- Boundaries are
UNBOUNDED PRECEDING,n PRECEDING,CURRENT ROW,n FOLLOWINGandUNBOUNDED FOLLOWING. - Cumulative frames give running totals, running maximums and cumulative percentages. Reversed frames give remaining totals. Sliding frames give moving averages.
ROWScounts rows,RANGEmeasures distance in theORDER BYvalue, andGROUPScounts groups of peers. They differ when the data has gaps or ties.- The default frame with
ORDER BYisRANGE ... UNBOUNDED PRECEDING AND CURRENT ROW, which includes peers. Write frames explicitly, and add tie-breakers toROWSframes. EXCLUDEremoves the current row or its peers from the frame.GROUPSandEXCLUDEaren't available in MySQL or SQL Server.
Practice questions
Write a query that shows each day's amount and the total of that day and the previous day.
Answer
SELECT day, amount,
SUM(amount) OVER (ORDER BY day ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS two_day_total
FROM daily_sales
ORDER BY day;
This uses the previous row, so 5 March is added to 3 March (210.00). To use the previous calendar day, write RANGE BETWEEN INTERVAL '1 day' PRECEDING AND CURRENT ROW, and 5 March gets just 60.00.
For each day, show the average of all the days after it. What does the last day show?
Answer
SELECT day, amount,
AVG(amount) OVER (ORDER BY day
ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING) AS avg_after
FROM daily_sales
ORDER BY day;
The last day's frame is empty, because no rows follow it, so AVG returns NULL.
SUM(price) OVER (ORDER BY category) gives the same value to both products in a category. Why, and how would you make it increase on every row?
Answer
With ORDER BY and no frame clause, the frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, which includes all peers: both products of the same category. Use ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW and make the order unique, for example ORDER BY category, product_id.
In SQL Server, AVG(amount) OVER (ORDER BY day RANGE BETWEEN 6 PRECEDING AND CURRENT ROW) is rejected. What are the alternatives?
Answer
SQL Server supports RANGE only with UNBOUNDED and CURRENT ROW boundaries. Either generate a row for every date (with a calendar table or GENERATE_SERIES in SQL Server 2022), left-join the sales to it and use ROWS BETWEEN 6 PRECEDING AND CURRENT ROW, or compute the average with a correlated subquery over the dates BETWEEN DATEADD(day, -6, day) AND day.
Which frame mode would you use for "the total of the last 3 distinct order dates", when several orders can share a date?
Answer
GROUPS BETWEEN 2 PRECEDING AND CURRENT ROW, with ORDER BY order_date. Each group is one date with all its orders, so the frame covers the current date and the two previous dates present in the data, whatever the number of rows per date. ROWS would count orders, and RANGE would count calendar days.
Previous: Ranking in SQL: ROW_NUMBER, RANK, DENSE_RANK, NTILE and Top-N per Group
Next: LAG, LEAD, FIRST_VALUE and LAST_VALUE: Comparing Rows With Their Neighbours

More in SQL Course
Quiz: SQL Dialect Differences (PostgreSQL, MySQL, SQL Server, Oracle, SQLite)
Twenty-four questions on how the major SQL databases differ: limiting rows, concatenation, empty strings, identifier case, upserts, identity columns, transactional DDL, error handling, isolation defaults, booleans, set operations, RETURNING, dates and typing.
Quiz: SQL Delicate Details
Twenty-five questions on SQL's subtle corners: NULLs in aggregates, IN and CHECK, sort order of NULLs, rounding, CHAR padding, window frame defaults, identity gaps, LIKE escapes, empty groups, set operations and multi-column updates.
Quiz: SQL Interview Questions
Thirty SQL questions of the kind asked in developer and analyst interviews: WHERE vs HAVING, DELETE vs TRUNCATE, keys, joins, duplicates, Nth-highest values, window functions, ACID, isolation, locking, indexes, views, procedures and performance.
Quiz: SQL Course Final Exam (All 15 Parts)
The final exam for the SQL course: thirty questions across all fifteen parts, from query processing, NULLs, joins and aggregation through windows, data changes, types, design, indexes, security, transactions, procedural SQL and tuning.
Discussion
Sign in to ask a question or share what you learned.