SQLSQL
#22

Filter Aggregated Groups with HAVING Clause in SQL

MediumAmazon
Interview Question #22
Asked at Amazon

From `orders`, find all `customer_id`s who have placed at least 5 orders AND whose total spend exceeds $10,000.

Input Table: orders
6 rows preview
order_idcustomer_idamount
11013000
21013000
31012500
41011500
5101500
610212000
Expected Output Structure1 rows
customer_idorder_counttotal_spend
101510500
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us