Filter Customers with High Transaction Totals
You’re analyzing customer spending patterns to identify users whose total transaction volume exceeds a set threshold.
This helps you prioritize high-value clients or spot unusual activity in the data.
You’ll use SUM() to calculate each customer’s total spending and HAVING to filter only those whose totals are above 400.
This lesson introduces post-aggregation filtering — a key concept when analyzing grouped results.
Task
From the transactions table in the bank_transactions.sqlite database, display:
customer_idtotal_spent(use an alias for the sum)
Only include customers whose total spending is greater than 400.
Sort results by total_spent in descending order.
How to solve it
Write a SQL query that calculates the total amount spent by each customer.
Use GROUP BY to aggregate by customer_id, and HAVING to filter for totals greater than 400.
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help
Code Editor
Tables
Execution Result