← All SQL interview questions

Cities with a loyal, high-spending buyer base

MediumHAVINGWalmartTarget

A regional expansion team looks for cities that already have both breadth and depth of demand.

From purchase_log, return city, the number of distinct buyers as buyer_count, and total spend as total_spend, keeping only cities that have at least 3 distinct customers and more than 20000 in total spend.

Sample data

Table: purchase_log

18 row(s) · showing first 8

purchase_idINTcityTEXTcustomer_codeTEXTamountNUMERIC(10,2)
1PuneCU-1019500.00
2PuneCU-1027200.00
3PuneCU-1036100.00
4PuneCU-1013400.00
5JaipurCU-20118000.00
6JaipurCU-2019000.00
7JaipurCU-2022500.00
8KochiCU-3014000.00

Practising alone only goes so far — our live cohorts pair SQL depth with dashboards, agentic analytics projects and mock interviews.

Explore the program