Best April deals - 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.customer_id,
  c.company_name,
  SUM(o.amount) AS total_revenue 
FROM orders o
JOIN customers c
  ON o.customer_id = c.customer_id
GROUP BY c.customer_id, c.company_name;

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 customer_id and company_name columns from the customers table.

Exercise

Show each category_id and category_name alongside the total_revenue generated by all order items from that category.

Stuck? Here's a hint!

Join the order_items and products and categories tables. Group by category_id and category_name.