The Silent Probe

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
L4
Asked in
Yelp

Problem

Some probes in svc_health never recorded a latency reading, so that column has gaps where a value should be. An on-call engineer needs every field of every health check reported with latency as a whole number, leaving out any record whose latency cannot be converted.

One probe never recorded. The rest still need reporting.

Tables

svc_health

Columns: check_id INTEGER, svc_name TEXT, status TEXT, latency REAL, uptime REAL, checked TEXT, region TEXT

svc_health: 10 of 200 rows
check_idsvc_namestatuslatencyuptimecheckedregion
137payment-apidegraded3.697.032026-02-02 01:05:00us-west-2
174user-svcunhealthy6.794.062026-03-03 02:10:00eu-west-1
211search-apitimeout9.891.092026-04-04 03:15:00ap-south-1
248gatewayHealthy12.998.122026-05-05 04:20:00eu-central-1
285notif-svcDEGRADED1695.152026-06-06 05:25:00us-east-1
322ml-servinghealthy19.192.182026-07-07 06:30:00us-west-2
359cache-svcdegradedNULL99.212026-08-08 07:35:00eu-west-1
396queue-workerunhealthy25.396.242026-09-09 08:40:00ap-south-1
433cron-svctimeout28.493.272026-01-10 09:45:00eu-central-1
470auth-svcHealthy31.590.32026-02-11 10:50:00us-east-1

Expected output

First 5 of 177 rows
check_idsvc_namestatuslatencyuptimecheckedregion
137payment-apidegraded397.032026-02-02 01:05:00us-west-2
174user-svcunhealthy694.062026-03-03 02:10:00eu-west-1
211search-apitimeout991.092026-04-04 03:15:00ap-south-1
248gatewayHealthy1298.122026-05-05 04:20:00eu-central-1
285notif-svcDEGRADED1695.152026-06-06 05:25:00us-east-1

Worked solution and explanation

What this problem is really about

Strip the data-quality framing away and this is a type conversion with a landmine in it. Most latency readings convert to a whole number cleanly, but 23 of the 200 checks carry a NULL where a probe never recorded anything. The tell is the phrase 'cannot be converted', because a bare CAST does not fail loudly on a NULL. It quietly hands back a NULL and keeps going. So the whole problem hinges on one decision: do you drop the rows you cannot convert, or let a NULL ride along inside a column you just promised was clean whole numbers? Miss it and you ship 200 rows where 177 belong, with holes in the 'cleaned' column.


Walking through it

Step 1: Find the rows that cannot convert

The sample rows already show one: 'cache-svc' has an empty latency where every other check has a decimal. That is the record the prompt calls unconvertible, and it is not alone in the full table. WHERE latency IS NOT NULL removes every one of them, not just a single id you happened to spot.

Step 2: Cast the survivors with CAST(latency AS INTEGER)

The cast truncates each surviving reading toward zero, so 3.6 becomes 3 and 31.5 becomes 31. The expected preview shows 3 for 3.6, not 4, which tells you plain truncation is wanted and rounding would grade wrong.

Step 3: Pass the other six columns through untouched

Every field is reported, so check_id, svc_name, status, uptime, checked and region come through as stored. The cast keeps the name latency, so the output reads like the source table. The mixed-case status values and the missing uptime readings stay as they are: cleaning those is not this sweep's job.


The solution

Filter the null, then cast
SELECT
    check_id,
    svc_name,
    status,
    CAST(latency AS INTEGER) AS latency,
    uptime,
    checked,
    region
FROM svc_health
WHERE latency IS NOT NULL

Common follow-up questions