This Year's Class

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

Problem

We're putting the 2025 signup class into our year-end growth report. Count how many users joined that year.

The cohort is in. Time to count who made it through the door.

Tables

users

Columns: user_id INTEGER, username TEXT, email TEXT, signup_date TEXT, account_status TEXT, age_bucket TEXT

users: 10 of 200 rows
user_idusernameemailsignup_dateaccount_statusage_bucket
100alicealice@example.com2025-02-02inactive25-34
197aaron42aaron42@example.com2026-03-03suspended35-44
294 ameliaamelia@example.com2024-04-04pending_verification45-54
391arjun arjun@example.com2025-05-05active55-64
488ava99ava99@example.com2026-06-06inactive65+
585andrew_kandrew_k@example.com2024-07-07suspendedNULL
682anikaanika@example.com2025-08-08 16:34:00pending_verification18-24
779aidenaiden@example.com2026-09-09 14:53:00active25-34
876aria_baria_b@example.com2024-10-10inactive35-44
973brianbrian@example.com2025-11-11suspended45-54

Expected output

First 1 of 1 rows
signup_count
59

Worked solution and explanation

What is really being asked

Strip off the year-end-report costume and this is one number: how many rows of users fall in calendar year 2025. The COUNT(*) is free. What separates candidates is the year test, because signup_date is TEXT and not every value has the same shape. Most read like '2025-11-11', but some carry a time of day, like '2025-08-08 16:34:00'. Assume every value is a bare date and that signup falls out of the class. Compare the year as a number and the count drops to zero. The answer is 59, and either mistake ships a confident wrong number into the report.

The count for the 2025 class
SELECT COUNT(*) AS signup_count
FROM users
WHERE strftime('%Y', signup_date) = '2025';

Extract the year from each signup_date, keep only 2025, then count the survivors.

Step 1: Reduce each date to its year

strftime('%Y', signup_date) hands back '2025' for both '2025-11-11' and '2025-08-08 16:34:00'. The time of day never enters the test, so every row is judged by its year alone, which is exactly the grain the report cares about.

Step 2: Compare against a string, not a number

strftime returns text, so the test is = '2025' with quotes. Writing = 2025 compares text to a number, which never matches, and the count silently comes back 0. If you would rather work in numbers, EXTRACT(YEAR FROM signup_date) = 2025 returns an integer and is graded the same.

Step 3: Count everyone who survives

COUNT(*) over the filtered rows is the whole class. Add no account_status filter: suspended, inactive and pending accounts all joined that year, and keeping only today's active ones shrinks the class to 9. Alias the count AS signup_count so the report column has a real name.

Assumes every value is a bare date
WHERE signup_date LIKE '2025-__-__' matches exactly ten characters, so '2025-08-08 16:34:00' fails the pattern and the count comes back 58.
Reads only the year
WHERE strftime('%Y', signup_date) = '2025' ignores whatever follows the date, so the timestamped signup stays in and the count is 59.

Common follow-up questions