Recap - Join
Part of the Fundamentals section of Coddy's SQL journey. Lesson 45 of 72.
Challenge
MediumAvailable tables and columns:
orders:id,customer_idproducts:id,unit_price,units_in_stockorder_items:id,order_id,product_id,quantity
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
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 columnsPractice on your own: SQL playground