The Ides of March

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

Domain
SQL
Difficulty
medium
Seniority
L3

Problem

The reliability team is auditing how the API holds up during March, when the spring promotions drive the year's heaviest traffic. For each endpoint, find its worst response time across any March on record, then order the endpoints from the one with the highest peak down to the one with the lowest.

Every endpoint has one March it would rather forget.

Tables

api_calls

Columns: call_id INTEGER, endpoint TEXT, method TEXT, status INTEGER, latency REAL, user_id INTEGER, call_time TEXT, err_msg TEXT

api_calls: 10 of 670 rows
call_idendpointmethodstatuslatencyuser_idcall_timeerr_msg
8079/api/v1/ordersPOST2004.21002026-02-02 01:07:00NULL
8158/api/v2/productsPUT2007.91972026-03-03 02:14:00NULL
8237/api/v1/searchDELETE20111.62942026-04-04 03:21:00NULL
8316/api/v1/auth/loginPATCH20415.33912026-05-05 04:28:00NULL
8395/api/v1/auth/logoutget30119NULL2026-06-06 05:35:00NULL
8474/api/v2/analyticspost40022.75852026-07-07 06:42:00Not found
8553/api/v1/paymentsGET40126.46822026-08-08 07:49:00Unauthorized
8632/api/v1/users/POST40330.17792026-09-09 08:56:00Rate limit exceeded
8711/api/v2/products/PUT40433.88762026-01-10 09:03:00Internal server error
8790/api/v1/usersDELETE50037.5NULL2026-02-11 10:10:00Bad gateway

Expected output

First 5 of 11 rows
endpointmax_latency
/api/v1/auth/logout1540.7
/api/v1/users1350.4
/api/v1/orders1160.1
/api/v2/products969.8
/api/v1/search779.5

Worked solution and explanation

What this is really asking

Strip the costume and this is a one-table extremes problem with a sneaky date predicate. The phrase 'any March on record' is doing all the work: you are not slicing one bounded date range, you are pulling the month component out of every timestamp and keeping the calls that land in month 03, no matter the year. Anyone can write MAX(latency) grouped by endpoint. The candidates who stumble are the ones who reach for a year-bounded date range, or compare the month to the integer 3, and quietly ship the wrong rows.

Building it step by step

Step 1: Pin the month, ignore the year

call_time carries a full timestamp, but the requirement only cares about the month. strftime('%m', call_time) extracts it as '01' through '12'. Filtering on = '03' in the WHERE clause keeps every March call across every year present in the table, which is exactly what 'any March on record' means.

Step 2: Collapse to one row per endpoint

Group the surviving March rows by endpoint and take MAX(latency). MAX skips nulls by design, so an endpoint that logged a missing latency on one call still reports its worst real number instead of disappearing from the result.

Step 3: Put the worst on top

Sort by the aggregated max_latency descending so the slowest endpoint sits first. The metric is the only sort key the answer depends on, so no extra tiebreaker is required to match the expected output.

Worst March latency per endpoint
SELECT endpoint, MAX(latency) AS max_latency
FROM api_calls
WHERE strftime('%m', call_time) = '03'
GROUP BY endpoint
ORDER BY max_latency DESC

One predicate isolates March of every year, then a plain grouped MAX gives the peak.

Year-bounded range (wrong)
WHERE call_time BETWEEN '2026-03-01' AND '2026-03-31' keeps only one year's March. Any endpoint whose worst March latency happened in a different year is understated or vanishes entirely.
Month extraction (right)
WHERE strftime('%m', call_time) = '03' keeps March from every year, so MAX(latency) truly reflects the worst March response time on record.

Common follow-up questions