Even-ID June Signups
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
- Bosch
Problem
The growth team is investigating a signup anomaly affecting June cohorts. Pull the full user profile for every June signup whose user ID is an even number, working up from the lowest user ID to the highest.
Odd IDs, even IDs. The filter is precise.
Tables
users
Columns: user_id INTEGER, username TEXT, email TEXT, signup_date TEXT, account_status TEXT, age_bucket TEXT
| user_id | username | signup_date | account_status | age_bucket | |
|---|---|---|---|---|---|
| 100 | alice | alice@example.com | 2025-02-02 | inactive | 25-34 |
| 197 | aaron42 | aaron42@example.com | 2026-03-03 | suspended | 35-44 |
| 294 | amelia | amelia@example.com | 2024-04-04 | pending_verification | 45-54 |
| 391 | arjun | arjun@example.com | 2025-05-05 | active | 55-64 |
| 488 | ava99 | ava99@example.com | 2026-06-06 | inactive | 65+ |
| 585 | andrew_k | andrew_k@example.com | 2024-07-07 | suspended | NULL |
| 682 | anika | anika@example.com | 2025-08-08 16:34:00 | pending_verification | 18-24 |
| 779 | aiden | aiden@example.com | 2026-09-09 14:53:00 | active | 25-34 |
| 876 | aria_b | aria_b@example.com | 2024-10-10 | inactive | 35-44 |
| 973 | brian | brian@example.com | 2025-11-11 | suspended | 45-54 |
Expected output
| user_id | username | signup_date | account_status | age_bucket | |
|---|---|---|---|---|---|
| 488 | ava99 | ava99@example.com | 2026-06-06 | inactive | 65+ |
| 2234 | cara_z | cara_z@example.com | 2026-06-24 | pending_verification | 35-44 |
| 3980 | fiona | fiona@example.com | 2026-06-14 | inactive | NULL |
| 5726 | jack | jack@example.com | 2026-06-04 | pending_verification | 45-54 |
| 7472 | leo99 | NULL | 2026-06-22 | inactive | 18-24 |
Worked solution and explanation
This is a two-condition row filter in a growth-investigation costume, and the only part that can really go wrong is how you read the month. signup_date is text, and 'June' means the month position of that text, whatever the year. Everyone writes the parity test. The candidates who slip match '06' anywhere in the string. LIKE '%06%' also catches the 6th of October and the 6th of September, and on this table four even-ID users dated the 6th of some other month end up in a June cohort that should hold six.
Read the requirements off the words
Step 1: Pull the month out of signup_date
Dates are stored as 'YYYY-MM-DD', and a couple of rows have a time of day appended. strftime('%m', signup_date) returns the two-character month, so comparing it to '06' keeps every June in every year and ignores the day and the time. The comparison is text to text: '06', not 6.
Step 2: Test the ID value, not the row position
user_id % 2 = 0 checks the ID itself. IDs here step by 97, so they alternate odd and even in a way that has nothing to do with where a row sits; numbering rows and keeping every second one picks a different set.
Step 3: Sort by user_id ascending
The ask is to work up from the lowest ID, so ORDER BY user_id. The ID is unique, so there is no tie to settle.
SELECT
user_id,
username,
email,
signup_date,
account_status,
age_bucket
FROM users
WHERE strftime('%m', signup_date) = '06'
AND user_id % 2 = 0
ORDER BY user_id- A substring match
signup_date LIKE '%06%'matches '06' wherever it sits, so the 6th of any month qualifies. On this table that adds four even-ID users dated the 6th of October, February or September: ten rows instead of six.- The month position
strftime('%m', signup_date) = '06'reads only the month. The day and a trailing time cannot leak in, and every year's June is kept.
Common follow-up questions
- How would you count the even-ID June signups per year instead of listing them? (Tests reading the year out of the same text date and grouping on it.)
- What changes if `signup_date` held Unix epoch seconds instead of text? (Tests converting to a date before taking its month.)
- At 18 million users, how would you make a month-of-year filter cheap? (Tests a stored month column or an expression index versus a full scan.)