Cheapest Cost Per Region

An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
easy
Seniority
L3
Asked in
Airbnb

Problem

The FinOps team wants to know the floor price they're paying in each region. Show the minimum cloud cost amount recorded for each region.

Lowest spend per region.

Tables

cloud_costs

Columns: cost_id INTEGER, provider TEXT, svc_name TEXT, region TEXT, amount REAL, acct_id TEXT, bill_date TEXT

cloud_costs: 10 of 200 rows
cost_idprovidersvc_nameregionamountacct_idbill_date
543GCPS3us-west-219.33acct-10012026-02-01
586AzureRDSeu-west-137.16acct-10022026-03-01
629awsLambdaap-southeast-154.99acct-10032026-04-01
672gcpBigQueryus-central172.82acct-10042026-05-01
715AWSCloud Runeurope-west190.65acct-10052026-06-01
758GCPBlob Storageus-east-1108.48acct-10062026-07-01
801AzureCosmos DBus-west-2126.31acct-10072026-08-01
844awsCloudFronteu-west-1144.14acct-10082026-09-01
887gcpPub/Subap-southeast-1161.97NULL2026-01-01
930AWSEC2us-central1179.8acct-10102026-02-01

Expected output

First 5 of 6 rows
regionmin_cost
ap-southeast-1-181.1
eu-west-1-137.4
europe-west1-268.5
us-central1-224.8
us-east-1108.48

Worked solution and explanation

This is a per-region floor, and the costume is the word 'price'. Anyone can produce one row per region. What separates candidates is whether they trust the data when five of the six floors come back negative. Those rows are credits and refunds on the bill, and they are the real lows. Add a WHERE amount >= 0 because 'a price cannot be negative', and five regions quietly report an inflated floor. Only 'us-east-1', which never got a credit, survives that edit.

Walk it through

Step 1: Keep one row per region

The ask is 'for each region', so the result has one row per value of region, six on this table. A bare SELECT MIN(amount) FROM cloud_costs answers a different question: one floor for the whole bill, -268.5, with no region attached.

Step 2: Take the low of amount exactly as recorded

MIN(amount) per region, named min_cost. Filter nothing first. The negatives are credits the region really received, and the twelve rows with no amount are already skipped by MIN on its own.

One floor per region
SELECT region, MIN(amount) AS min_cost
FROM cloud_costs
GROUP BY region
Filters the credits
WHERE amount >= 0 runs before grouping, so 'eu-west-1' reports a positive floor instead of -137.4. The same happens to every region whose lowest line is a credit.
Reads the bill as it is
No filter. MIN(amount) sees every recorded line, so 'europe-west1' lands at -268.5 and 'us-east-1' at 108.48, matching what finance actually booked.

Common follow-up questions