Menu
Coddy logo textTech

Recap - Coffee Shop

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

challenge icon

Challenge

Medium

Available 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