Deploy Count by Service

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
Asana

Problem

Every deployment attempt counts here, whether it succeeded, failed, rolled back or is still in progress. An engineer scoping a deployment automation project needs each service's total deployment count from deploy_logs, most frequently deployed first.

Some services deploy constantly. Others barely at all.

Tables

deploy_logs

Columns: log_id INTEGER, svc_name TEXT, version TEXT, env_name TEXT, status TEXT, deploy_at TEXT, dur_secs INTEGER, author TEXT

deploy_logs: 10 of 200 rows
log_idsvc_nameversionenv_namestatusdeploy_atdur_secsauthor
131payment-apiv1.0.2stagingfailed2026-02-02 01:11:0023bob
162user-svcv1.1.0devrolled_back2026-03-03 02:22:0036charlie
193search-api2.0.0canaryin_progress2026-04-04 03:33:0049dana
224gatewayv2.1.0ProductionSuccess2026-05-05 04:44:0062eve
255notif-svc2.1.1STAGINGFAILED2026-06-06 05:55:0075frank
286analyticsv3.0.0-rc1productionsuccess2026-07-07 06:06:0088Alice
317ml-servingv1.0.3stagingfailed2026-08-08 07:17:00NULLBOB
348auth-svcv1.0.1devRolled_Back2026-09-09 08:28:00114alice
379Payment-APIv1.0.2canaryin_progress2026-01-10 09:39:00127bob
410user-svcv1.1.0ProductionSuccess2026-02-11 10:50:00140charlie

Expected output

First 5 of 11 rows
svc_namedeploy_count
user-svc26
search-api26
notif-svc24
payment-api23
payment-api 1

Worked solution and explanation

What this really is

Strip off the automation-project framing and this is a per-service tally with the sort pointed at the tally, not at the name. Everyone writes COUNT(*). What separates answers is what they quietly add or leave out: a WHERE status = 'success' that throws away every failed and rolled-back attempt, or an ORDER BY svc_name that lists services alphabetically. Either one and the busiest services stop sitting at the top, so the automation work starts in the wrong place.

Step 1: Count every attempt, not every success

status mixes 'failed', 'rolled_back', 'in_progress' and a few case variants. Each row is still a deployment someone ran, so nothing gets filtered. COUNT(*) counts rows, which is exactly the unit the question is about.

Step 2: Collapse to one row per svc_name

GROUP BY svc_name turns 200 log rows into one row per service name. Without it, COUNT(*) next to svc_name either errors or folds the whole table into one total. SELECT DISTINCT svc_name gives you the names with no tally at all.

Step 3: Sort by the tally, biggest first

ORDER BY deploy_count DESC sorts on the alias. 'gateway' and 'search-api' both land on 26, and the question says nothing about which comes first. Either order is correct, so no tiebreaker is owed.

Deployments per service, busiest first
SELECT svc_name, COUNT(*) AS deploy_count
FROM deploy_logs
GROUP BY svc_name
ORDER BY deploy_count DESC

Common follow-up questions