Skip to content
Lab 2 of 4

Joins & Aggregation: Answering Real Questions

Data spread across customers, products and orders only becomes answers when you join and aggregate it. Build views that compute order totals, rank spending, and find the customers a simple query would miss.
  • Intermediate
  • 45 min
  • SQL
  • Joins
  • Aggregation
  • PostgreSQL

Overview

A normalized database stores facts in separate tables; the interesting questions live in the relationships between them. This lab gives you a seeded shop database — customers, products, orders — and asks the questions a business actually cares about.

You'll write the joins and aggregations as named views (so each answer is reusable and checkable): per-order line totals, total spend per customer, the big spenders above a threshold, and — the one beginners always miss — the customers with no orders at all, which only a LEFT JOIN will reveal. By the end, JOIN, GROUP BY, HAVING and LEFT JOIN are tools you reach for without thinking.

What you will learn

  • Combine three tables with INNER JOIN
  • Compute per-row values (price × quantity) in a query
  • Aggregate with SUM and GROUP BY to total spend per customer
  • Filter aggregated groups to find big spenders
  • Use a LEFT JOIN ... IS NULL to find rows with no match

Before you start

  • Designing a Schema with Constraints first, or basic SQL
  • You understand tables, rows and columns

Tasks

  1. 01Join orders to customers and products
  2. 02Total spend per customer
  3. 03Find the big spenders
  4. 04Find the customers with no orders

Next in this course