Instruction
Well done! In business reports, we often want to calculate certain metrics for multiple business objects at the same time. For instance:
SELECT o.order_id, COUNT(*) AS order_items_count FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.order_id BETWEEN 10200 AND 10300 GROUP BY o.order_id;
In the query above, we count the number of items in each order with an order_id in the specified range. By joining the orders and order_items tables, we can display information about a single order item and its parent order on the same row. Then, we group all rows by their parent order and use COUNT(*) to find the number of items in each order.
Exercise
Show each supplier_id alongside the company_name and the number of products they supply (as the products_count column). Use the products and suppliers tables.
Stuck? Here's a hint!




