Menu
Coddy logo textTech

Recap - Boxes

Part of the Fundamentals section of Coddy's SQL journey — lesson 64 of 72.

challenge icon

Challenge

Easy

Available 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:

  1. Create a column named can_fit_next that 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
  2. Filter to show only the boxes that can fit into the next box (where can_fit_next = 1)
  3. Return the box_id
  4. Order the results by box_id in ascending order

Try it yourself

All lessons in Fundamentals