~/ learn/ comp-378/ cards/ Multi-Table Aggregation: 3–4 Table Joins with GROUP BY
1 of 5

Type the four-table sales chain with a grouped SUM:

Type the four-table sales chain with a grouped SUM:

Answer

SELECT c.name, SUM(ol.qty) AS units FROM customers c JOIN orders o ON o.customer_id = c.customer_id JOIN order_lines ol ON ol.order_id = o.order_id JOIN products p ON p.product_id = ol.product_id GROUP BY c.name;

customers→orders→order_lines→products is the standard sales chain: three ON conditions reach four tables; GROUP BY c.name aggregates per customer.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/7dd2fb65-bfdb-4ebd-be79-56bd2373c224/flashcard utf-8 LF