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
| log_id | svc_name | version | env_name | status | deploy_at | dur_secs | author |
|---|---|---|---|---|---|---|---|
| 131 | payment-api | v1.0.2 | staging | failed | 2026-02-02 01:11:00 | 23 | bob |
| 162 | user-svc | v1.1.0 | dev | rolled_back | 2026-03-03 02:22:00 | 36 | charlie |
| 193 | search-api | 2.0.0 | canary | in_progress | 2026-04-04 03:33:00 | 49 | dana |
| 224 | gateway | v2.1.0 | Production | Success | 2026-05-05 04:44:00 | 62 | eve |
| 255 | notif-svc | 2.1.1 | STAGING | FAILED | 2026-06-06 05:55:00 | 75 | frank |
| 286 | analytics | v3.0.0-rc1 | production | success | 2026-07-07 06:06:00 | 88 | Alice |
| 317 | ml-serving | v1.0.3 | staging | failed | 2026-08-08 07:17:00 | NULL | BOB |
| 348 | auth-svc | v1.0.1 | dev | Rolled_Back | 2026-09-09 08:28:00 | 114 | alice |
| 379 | Payment-API | v1.0.2 | canary | in_progress | 2026-01-10 09:39:00 | 127 | bob |
| 410 | user-svc | v1.1.0 | Production | Success | 2026-02-11 10:50:00 | 140 | charlie |
Expected output
| deploy_date | deploy_count |
|---|---|
| 2022-01-02 | 1 |
| 2022-01-06 | 1 |
| 2022-02-03 | 2 |
| 2022-03-24 | 1 |
| 2026-01-17 | 2 |
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
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_atmakes 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
- How would you include days that had zero deployments? (Tests a calendar table or `generate_series` joined back with an outer join.)
- How would you show the running total of deployments over time? (Tests `SUM(COUNT(*)) OVER (ORDER BY deploy_date)` layered on the daily count.)
- What changes if `deploy_at` is stored as a Unix epoch integer instead of a timestamp? (Tests `TO_TIMESTAMP` conversion before the date is derived.)