Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW tells a window aggregate to include every ordered row from the start of the current partition through the current row. For LeetCode 1204, that makes SUM(weight) a running total in boarding order; the last passenger whose total stays at or below 1,000 kilograms is John Cena.
What is a window frame in SQL?
A window function calculates a value using related rows while keeping each input row in the result. A window frame is the subset of those rows used for the current row’s calculation. As the current row changes, the frame can move with it. PostgreSQL explains how frame-sensitive aggregate functions operate on the rows in the current frame in its Window Functions documentation.
As an Amazon Associate I earn from qualifying purchases.
For a running total, each row needs the values from the beginning of the ordered data through that row. The frame clause states those boundaries explicitly.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
What do UNBOUNDED PRECEDING and CURRENT ROW mean?
Consider this window expression:
SUM(weight) OVER (
ORDER BY turn
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS cumulative_weight
ORDER BY turnsets the sequence in which the calculation advances. In LeetCode 1204, theturncolumn gives the boarding order.UNBOUNDED PRECEDINGsets the frame’s starting boundary at the first row of the current partition. It does not mean the query scans rows before that partition.CURRENT ROWsets the ending boundary. WithROWS, it means the current row itself.SUM(weight)adds the weights in that frame. Each output is therefore the total weight from the first turn through the current turn.
In short, “unbounded” means there is no earlier starting offset within the partition; it does not mean an infinite set of rows.
#1 Best Overall
How ROWS differs from RANGE when sort values tie
The distinction matters when multiple rows have the same value in the window’s ORDER BY. Such rows are peers. With ROWS, CURRENT ROW ends at the current physical row in the ordered sequence. With RANGE, the current-row boundary includes the current row’s peers, so tied rows can receive the same aggregate result. MySQL describes frames and peer handling in its Window Function Frame Specification; PostgreSQL also explains peer-aware frames in its Window Functions documentation.
For a row-by-row running total, write ROWS explicitly. If the ordering column is not unique, add a unique tie-breaker when the desired row sequence requires one. LeetCode 1204 defines distinct turns, so ORDER BY turn establishes the example’s order.
Rank #2
- Comprehensive Coverage: SQL Flashcards and NoSQL Flashcards designed for beginners and interview prep, covering core database concepts, queries, indexing, normalization, and real-world use cases. From relational structures, JOINs, and indexing to NoSQL document models, key-value stores, and distributed systems, these flashcards give you a solid foundation and advanced knowledge to handle any database challenge confidently.
- Interactive Learning: Enhance your understanding with an interactive, hands-on approach. Each card includes practical query examples, schema illustrations, and exercises that let you immediately apply what you learn. This active learning style helps you strengthen your querying skills and build intuition for solving real data problems. Beginner-friendly explanations that help you learn SQL and NoSQL faster without overwhelming theory or dense textbooks
- Portable Convenience: Study databases anytime, anywhere. Whether you’re at home, commuting, or taking a break, these portable flashcards make it easy to learn on the go. Perfect for busy students, developers, or professionals fitting learning into a tight schedule.
- Versatile Audience: Designed for all learners from students preparing for exams to data analysts, backend engineers, and tech enthusiasts. Whether you're building your first query or optimizing production databases, these flashcards guide you at every stage of your learning journey. Perfect for SQL interview preparation for software engineers, data analysts, backend developers, and computer science students
- Skill Enhancement: Boost your confidence and stay current with evolving database technologies. Ideal for self-study, bootcamps, university courses, and last-minute interview revision with concise, memorable flashcard format
LeetCode 1204: find the last passenger who fits
The problem gives a Queue table with person_id, person_name, weight, and turn. Passengers board by turn, and the bus limit is 1,000 kilograms. The original statement and example are on LeetCode 1204: Last Person to Fit in the Bus.
Sort the example by boarding order, then apply the running sum:
| Turn | Person | Weight (kg) | Cumulative weight (kg) | Outcome |
|---|---|---|---|---|
| 1 | Alice | 250 | 250 | Fits |
| 2 | Alex | 350 | 600 | Fits |
| 3 | John Cena | 400 | 1,000 | Fits; last passenger within the limit |
| 4 | Marie | 200 | 1,200 | Exceeds the limit |
| 5 | Bob | 175 | Not needed | The limit was already exceeded at turn 4 |
| 6 | Winston | 500 | Not needed | The limit was already exceeded at turn 4 |
At turn 3, the cumulative weight is exactly 1,000 kilograms, so John Cena still fits. Marie’s addition raises the total to 1,200 kilograms. Because everyone boards in turn order, later passengers cannot become the last person to fit after the queue has already crossed the limit.
Query using an explicit window frame
WITH running_weights AS (
SELECT
person_name,
turn,
SUM(weight) OVER (
ORDER BY turn
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS cumulative_weight
FROM Queue
)
SELECT person_name
FROM running_weights
WHERE cumulative_weight <= 1000
ORDER BY turn DESC
LIMIT 1;
The inner query gives each passenger the cumulative weight through their turn. The outer query keeps only passengers whose cumulative total is no greater than the capacity, then returns the eligible passenger with the greatest turn. The problem’s test cases ensure that the first passenger is within the limit.
Rank #4
Should you rely on the default frame?
Defaults depend on the database engine and the function. The cited manuals for MySQL 8.4, PostgreSQL, and SQL Server describe an ordered window without an explicit frame as using RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW for the relevant aggregate-window behavior. That includes peers at the current ordering value, rather than necessarily stopping at one physical row. See the MySQL 8.4 frame specification, PostgreSQL’s Window Functions and SELECT documentation, and Microsoft’s OVER Clause (Transact-SQL).
An explicit ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW makes the row-by-row intent visible instead of relying on a default. For production queries, check the documentation for the specific database engine and version you use.
Quick Recap
Best Value
- Funny programmer gift for software developers and computer scientists. This coding design shows a fun SQL query for database admins and nerds.
- Cool SQL Database gift for men and women who love SQL. The perfect SQL Query gift for programmers, hackers and SQL database fans who love relational databases.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




