Active Users With April Transactions

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
Google

Problem

The growth team is measuring transacting reach for April 2026. How many users with active accounts completed at least one transaction during that month? Return a single count.

Active accounts that also opened their wallets. How many?

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

transactions

Columns: transaction_id INTEGER, user_id INTEGER, product_id INTEGER, quantity INTEGER, total_amount REAL, transaction_date TEXT

transactions: 10 of 200 rows
transaction_iduser_idproduct_idquantitytotal_amounttransaction_date
10671971001223.462026-02-02
11342941050336.932026-03-03
12013911099450.42026-04-04
12684881148563.872026-05-05
13355851197002026-06-06
14026821246290.812026-07-07
146977912953104.282026-08-08
153687613444117.752026-09-09
160397313935-452026-01-10
1670107014421144.692026-02-11

Expected output

First 1 of 1 rows
active_users_with_transactions
1

Worked solution and explanation

Why this problem exists in real interviews

Working with users, transactions, this problem isolates grouped aggregation. The interviewer expects candidates to articulate why username, email, signup_date matter for correctness before touching the keyboard.


Break down the requirements

Step 1: Join users with transactions

Join users to transactions on user_id to link each transaction to its account.

Step 2: Group by account_status

Filter to active accounts (account_status = 'active') whose transaction falls in April of 2026 via strftime year/month.

Step 3: Aggregate with MIN

Return COUNT(DISTINCT u.user_id) so each qualifying user is counted once as a single reach figure.

Step 4: Order by the metric

Sort descending to surface the top values first.


The solution

Group-aggregate for active users april transactions
SELECT COUNT(DISTINCT u.user_id) AS active_users_with_transactions
FROM users u
JOIN transactions t ON u.user_id = t.user_id
WHERE u.account_status = 'active'
  AND strftime('%Y', t.transaction_date) = '2026'
  AND strftime('%m', t.transaction_date) = '04'

Common follow-up questions