Menu
Coddy logo textTech

Recap - Scooter Shop

Part of the Fundamentals section of Coddy's SQL journey. Lesson 41 of 72.

challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>scooters</strong>: <strong>model</strong>, <strong>brand</strong>, <strong>has_lights</strong>, <strong>price</strong>

As the manager of a scooter shop, you have noticed that many scooters are not original, meaning they are missing a model name. Furthermore, bad scooters typically do not have lights.

Your task involves two steps:

  1. First, Add to all scooter prices in the shop the overall average price.
  2. Then, Calculate the average price for each brand, considering only good and original scooters (i.e., scooters with a model name and lights).

The result should include the brand and the average price - avg_price. Sort the results by the average price in ascending order.

Try it yourself

-- Step 2: filter the rebuilt rows, then average them per group
SELECT ____
FROM (
    -- Step 1: rebuild every row, replacing the value with the adjusted one
    SELECT model, brand, has_lights, ____ AS price
    FROM scooters
)
WHERE ____ AND ____
GROUP BY ____
ORDER BY ____

All lessons in Fundamentals

Practice on your own: SQL playground