Recap - Coffee Shop
Part of the Fundamentals section of Coddy's SQL journey — lesson 42 of 72.
Challenge
MediumAvailable tables and columns:
<strong>beans</strong>:<strong>brand</strong>,<strong>density</strong>,<strong>diameter_wide</strong>,<strong>shade</strong>
You are the owner of a coffee shop. There are many customers that are waiting for their orders. You may use only one type of coffee beans every day.
There are several criteria for selecting which beans to use. First, we need to filter the beans based on these conditions:
- All beans must have a diameter greater than the average diameter of all beans in the table
- For light beans: keep only those where the ratio of density to diameter is greater than
0.01 - For dark beans: keep all of them
- For semi-dark beans: exclude all of them (they are considered unsuitable)
For each brand that meets these criteria, calculate their average density. Only keep brands where the average density is less than 0.8.
Return the brand name and their average density (name the column avg_density) rounded to 3 decimal places. Sort the results by average density 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() 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