Ship It or Skip It

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
Vesta Innovations

Problem

How many deploys did we ship on each calendar day, going by the timestamps in our deploy_logs? List the days from earliest to latest.

The calendar doesn't lie. How aggressive is this team, really?

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 183 rows
deploy_datedeploy_count
2022-01-021
2022-01-061
2022-02-032
2022-03-241
2026-01-172

Worked solution and explanation

What this problem really is

This is calendar bucketing wearing a deployment-velocity costume. deploy_at is stored to the second, so the day is not a column you can read: it is a value you derive before you count. Anyone can write COUNT(*). The thing that separates candidates is noticing the time of day riding along in every timestamp. Group on the raw deploy_at and you get one row per deploy instant, almost every count a 1, instead of the 183 days where several dates carry two deploys.


Break down the requirements

Step 1: Derive the day from deploy_at

deploy_at is text like '2026-02-02 01:11:00'. The day you are asked about is only its date part, so compute DATE(deploy_at) and make that the grouping key. Two deploys at 01:11 and 22:40 on the same date now land in one bucket.

Step 2: Count every row in the bucket

COUNT(*) is the right measure: every logged deploy counts, including a second push of the same service that day, so there is nothing to make unique first.

Step 3: Sort by the derived day

Order by the deploy_date alias, oldest first. Each day appears exactly once, so the date alone fixes the sequence and no tiebreaker is owed.


The solution

Date-grouped count
SELECT DATE(deploy_at) AS deploy_date,
       COUNT(*) AS deploy_count
FROM deploy_logs
GROUP BY DATE(deploy_at)
ORDER BY deploy_date
Grouping on the stored value
GROUP BY deploy_at makes one group per recorded second. On this table that is roughly one row per deploy, each with a count of 1, and every day with two deploys is split in half.
Grouping on the derived day
GROUP BY DATE(deploy_at) drops the time of day first, so every deploy on a date shares one key and each calendar day comes back once with its true total.

Common follow-up questions