Lecture

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_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.

sqlQuiz
?

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Tables

Execution Result