Menu
Coddy logo textTech

Recap - Join

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

challenge icon

Challenge

Medium

Available tables and columns:

  • <strong>orders</strong>: <strong>id</strong>, <strong>customer_id</strong>
  • <strong>products</strong>: <strong>id</strong>, <strong>unit_price</strong>, <strong>units_in_stock</strong>
  • <strong>order_items</strong>: <strong>id</strong>, <strong>order_id</strong>, <strong>product_id</strong>, <strong>quantity</strong>

Find the customer IDs of customers who have ordered products with a unit price less than 10, and list the total quantity of those cheap products each customer has ordered.

Return following columns:

  • customer_id
  • total_quantity (the sum of quantities of products with a unit price < 10 for each customer)

Try it yourself

-- List the grouping column and the aggregated value the task asks for
SELECT ____
FROM orders
-- Each join needs a condition matching an id column to the column that points at it
INNER JOIN order_items ON ____
INNER JOIN products ON ____
-- Then keep only the rows that meet the threshold the task describes
WHERE ____
GROUP BY orders.customer_id;

All lessons in Fundamentals

Practice on your own: SQL playground