Memra

Capstone: a real report

Put every tool together in one query.

Bring it all together

Time to combine joins, aggregation, and ordering into a genuine business report — the kind you'd actually be asked for.

The brief: the shop wants a customer leaderboard. For every customer who has spent anything, show their name and total amount spent across all their orders (sum of quantity × unit_price), with the biggest spender first.

This needs: a join from customers through orders and order_items, a SUM over the line items, a GROUP BY the customer, and an ORDER BY the total. You've done every piece — now assemble it.

NORMAL ~/memra/learn/postgresql/capstone utf-8 LF