Skip to main content
SQL • LESSON 89

JOIN with GROUP BY

How can we calculate total orders for every customer?

Advanced3 Minutes1020 XP
🤔 THE QUESTION

How can we calculate total orders for every customer?

💡 WHAT IS IT?

Joining dimension and fact tables followed by GROUP BY calculates metrics per parent dimension.

🎯 WHAT IS IT USED FOR?

Order frequency per customer, activity metrics, customer summary tables.

💻 EXAMPLE
SELECT c.customer_name, COUNT(o.order_id) AS order_count
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id
GROUP BY c.customer_name;

🎯 Mission Objectives

Practice typing production-grade SQL code for JOIN with GROUP BY.

  • JOIN + GROUP BY
  • Customer order count
  • Dimension aggregation
  • Fact table rollups