Skip to main content
Practice

Filter Customers with High Transaction Totals

You're reviewing customer spending patterns and need to highlight users whose total transaction volume exceeds a certain threshold.

This helps prioritize outreach to high-value customers or detect unusual activity.

To do this, you'll use SUM() to calculate total spending per customer, and HAVING to filter only those with totals above 400.

This lesson introduces post-aggregation filtering—an essential step when working with grouped summaries.


Task

From the transactions table in the bank_transactions.sqlite database, display:

  • customer_id
  • total_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.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.