Recap challenge #2
Lesson 8 of 13 in Coddy's SQL for advanced course.
Challenge
EasyBoxes have many use cases. We want to check if we can fit every box in the next box.
If the size of the next box is greater than the current box, then we can fit it in the next box.
Add a column named can_fit_next that represents a boolean (1 or 0) indicating whether the box can fit in the next box.
The last box should have an empty value because it does not have a next box.
Boxes of the same size cannot fit.
Filter all boxes that cannot be fitted, and only for the boxes that can be fitted, check again if the boxes can be fit.
Return the box_id and the can_fit_next column after running it twice.
Order the results by box_id in ascending order.
Try it yourself
All lessons in SQL for advanced
4Summary
Final challenge #12Window Functions part 1
ROW_NUMBER functionORDER BY criterionPARTITION BY criterionLEAD & LAG functionsRecap challenge #1Recap challenge #23Window Functions part 2
RANK & DENSE_RANK functionsNTILE functionAggregation functionsROWS & RANGE criterion