Annual Cloud Spend Summary

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
Uber

Problem

The annual infrastructure review needs a slide showing how cloud spend and service sprawl have grown, walking the timeline from the earliest fiscal year up to the most recent. For each fiscal year, report the total amount spent and how many unique services appeared on the bill.

A year of cloud bills. Add it all up.

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 5 rows
fiscal_yeartotal_spendservice_count
202215743.7200000000012
202316482.792
202417221.862
202517960.932
202689733.710

Worked solution and explanation

Why this problem exists in real interviews

Working with cloud_costs, this problem isolates date extraction and truncation. The interviewer expects candidates to articulate why provider, svc_name, region matter for correctness before touching the keyboard.


Break down the requirements

Step 1: Group by STRFTIME('%Y'

Group cloud_costs rows by fiscal year, extracted from bill_date with strftime('%Y', ...).

Step 2: Compute SUM(amount)

Sum amount per year to get total_spend, and use COUNT(DISTINCT svc_name) to count the unique services on the bill.

Step 3: Order by the metric

Order by fiscal_year so the per-year rows come out in a stable, deterministic sequence for the slide.


The solution

Date-extract for annual cloud spend summary
SELECT strftime('%Y', bill_date) AS fiscal_year,
       SUM(amount) AS total_spend,
       COUNT(DISTINCT svc_name) AS service_count
FROM cloud_costs
GROUP BY strftime('%Y', bill_date)
ORDER BY fiscal_year;

Common follow-up questions