medium10 pts · first answer countssqljoinsaggregation
Counting orders for every customer
customers A, B, C. orders: A has 2, B has 1, C has none. The query groups a LEFT JOIN by customer. What does it show for C in each column?
SELECT c.name, COUNT(*) AS a, COUNT(o.id) AS b FROM customers c LEFT JOIN orders o ON o.customer_id = c.id GROUP BY c.name;
Discussion 0
Join free to post in the discussion.
Related questions
- Purpose of a primary keyData Engineer
- Row count of a LEFT JOINData Engineer
- Filtering with = NULLData Engineer
- COUNT(*) vs COUNT(column)Data Engineer
- Filtering groups with HAVINGData Engineer
- Adding a number to NULLData Engineer
- Orders pointing to missing customersData Engineer
- Joining with a small lookup tableData Engineer