Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Providing detailed information and counting objects
Calculating metrics for multiple business objects
5. Computations for multiple objects
Understanding the difference between various count metrics
Summary

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.OrderID,
  COUNT(*) AS OrderItemsCount
FROM Orders O
JOIN OrderItems OI
  ON O.OrderID = OI.OrderID
WHERE O.OrderID BETWEEN 10200 AND 10300
GROUP BY O.OrderID;

In the query above, we count the number of items in each order with an OrderID in the specified range. By joining the Orders and OrderItems 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 SupplierID alongside the CompanyName and the number of products they supply (as the ProductsCount column). Use the Products and Suppliers tables.

Stuck? Here's a hint!