Menu
Coddy logo textTech

Recap - Bar Beverage Container

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

challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>beverages</strong>: <strong>id</strong>, <strong>current_year</strong>, <strong>expiration_year</strong>

Your bar stocks a vast selection of juices, and you need to identify which ones require attention. Identify and sort these juices based on the following clear criteria:

  1. Old Expired Juices
    1. Juices where the expiration year is MORE than 6 years before the current year (current_year - expiration_year > 6)
    2. These need to be recycled immediately
  2. Almost Expired Juices
    1. Juices expiring in the current year
    2. OR juices expiring next year (expiration_year = current_year + 1)
    3. These need to be sent for renewal

Follow these steps:

  • Extract the IDs of juices that meet either of these criteria
  • Rename the ID column to 'to_renew'
  • Sort results by processing priority:
    • Most urgent first (oldest expired juices)
    • Then almost expired juices
    • Use (current_year - expiration_year) for sorting

Try it yourself

All lessons in Fundamentals