Recap - Boxes
Part of the Fundamentals section of Coddy's SQL journey — lesson 64 of 72.
Challenge
EasyAvailable tables and columns:
<strong>boxes</strong>:<strong>box_id</strong>,<strong>size</strong>
We want to check if each box can fit inside the next box in sequence (where sequence is ordered by box_id). A box can fit in the next box if the next box's size is greater than the current box. Write a query to compare each box with the next box in sequence. A box can fit into the next box if and only if the next box's size is strictly greater than the current box's size. Follow these steps:
- Create a column named
can_fit_nextthat shows:- 1 (true) if the box can fit into the next box
- 0 (false) if it cannot fit
- The last box will automatically get NULL as there is no next box to compare with
- Filter to show only the boxes that can fit into the next box (where can_fit_next = 1)
- Return the
box_id - Order the results by box_id in ascending order
Try it yourself
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function8Statistics
Built-In Aggregate Part 1Built-In Aggregate Part 2Grouping Part 1Grouping Part 2Subqueries Part 1Subqueries Part 2Recap - Total Gain ShopRecap - Scooter ShopRecap - Coffee Shop11Window Functions part 1
ROW_NUMBER functionORDER BY criterionPARTITION BY criterionPARTITION & ORDERLEAD & LAG FunctionsRecap - LEAD & LAGRecap - PicturesRecap - Boxes3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns