Recap - Bar Beverage Container
Part of the Fundamentals section of Coddy's SQL journey — lesson 29 of 72.
Challenge
EasyAvailable 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:
Old Expired Juices- Juices where the expiration year is MORE than 6 years before the current year (
current_year - expiration_year > 6) - These need to be recycled immediately
- Juices where the expiration year is MORE than 6 years before the current year (
Almost Expired Juices- Juices expiring in the current year
- OR juices expiring next year (
expiration_year = current_year + 1) - 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
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() Function3Specific 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