runtime
Warehouse and Reporting · milestone 06 / 06

milestone 6/6 Customer & product reporting contracts

Produce customer and product reports at a defined level of detail.

Warehouse and Reporting · Profile raw CRM/sales records, build Silver and Gold tables in the disposable lab, explore the fact table, and publish repeatable reporting logic.

approach

A reusable report combines identity, totals, dates, and meaningful segmentation at one entity grain. Preserve entities with no sales when requested. These exercises define recency against 2025-04-01 rather than today, so the answer is reproducible.

worked-example.sql
SELECT
  c.customer_id,
  c.name,
  COUNT(f.sale_key) AS sales_lines,
  COALESCE(SUM(f.sales),0) AS total_sales
FROM dim_customer c
LEFT JOIN fact_sales f ON f.customer_key=c.customer_key
GROUP BY c.customer_key,c.customer_id,c.name;

data for this milestone

dim_customer4 columns · 5 rows
customer_keyinteger · keycustomer_idtextnametextcountrytext
1C001Alice NguyenUnited States
2C002BenUnited Kingdom
3C003CaraUnited Kingdom
4C004DevIndia
5C005ElenaCanada

all 5 rows

fact_sales6 columns · 9 rows
sale_keyinteger · keycustomer_keyintegerproduct_keyintegerquantityintegersalesrealorder_datetext
1112242025-01-01
2231802025-01-02
3121452025-01-15
43422402025-02-01
54321602025-02-05

showing 5 of 9 rows

dim_product5 columns · 4 rows
product_keyinteger · keyproduct_idtextnametextcategorytextpricereal
1P01NotebookStationery12
2P02Desk lampHome45
3P03KeyboardTech80
4P04HeadphonesTech120

all 4 rows

challenge 1

Return customer_id,name,sales_lines,total_sales,recency_days for every dim_customer. Missing sales total=0; recency=NULL with no sales. Recency = days from last order_date to 2025-04-01, integer.

Return customer_idnamesales_linestotal_salesrecency_daysany row order

challenge-1.sql
 
3 steps left · check both queries and pass the concept checkOpen the report
Customer & product reporting contracts — Warehouse and Reporting · Runtime