Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Get to know the database
Basic revenue metrics
Summary

Instruction

Excellent! Now let's see how we can show the revenue generated by various groups to date. For instance:

SELECT
  C.CustomerId,
  C.CompanyName,
  SUM(O.Amount) AS TotalRevenue 
FROM Orders O
JOIN Customers C
  ON O.CustomerId = C.CustomerId
GROUP BY C.CustomerId,
  C.CompanyName;

The query above shows the revenue to date for each customer. To find the total amount for each customer, we group the whole query by the CustomerId and CompanyName columns from the Customers table.

Exercise

Show each CategoryId and CategoryName alongside the TotalRevenue generated by all order items from that category.

Stuck? Here's a hint!

Join the OrderItems and Products and Categories tables. Group by CategoryId and CategoryName.