# Active Users With April Transactions

> Active accounts that also opened their wallets. How many?

Canonical URL: <https://datadriven.io/problems/active_users_with_april_transactions>

Domain: SQL · Difficulty: easy · Seniority: L3

## 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.

## 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`

Use `JOIN` on `user_id` to link fact rows to the dimension table. INNER JOIN keeps only matched rows.

#### Step 2: Group by `account_status`

`GROUP BY a.account_status` produces one row per distinct value of the grouping column.

#### Step 3: Aggregate with MIN

`MIN(quantity)` computes the metric at the grouped grain.

#### Step 4: Order by the metric

Sort descending to surface the top values first.

---

### The solution

**Group-aggregate for active users april transactions**

```sql
SELECT
    a.account_status,
    MIN(quantity) AS min_quantity
FROM users a
JOIN transactions b ON a.user_id = b.user_id
WHERE account_status = 'active'
GROUP BY a.account_status
ORDER BY min_quantity DESC
```

> **Cost Analysis**
>
> The main table has 20M rows (5 GB). The GROUP BY reduces the row count early, keeping downstream operations cheap. An index on the filter or join column would improve performance at scale.

> **Interviewers Watch For**
>
> Strong candidates state the correct `GROUP BY` grain before writing any SQL, showing they think about the output shape first. Join type selection (INNER vs LEFT) reveals whether the candidate read the requirements carefully.

> **Common Pitfall**
>
> Selecting a non-aggregated column without including it in `GROUP BY` is the most common error. Some engines reject it; others silently return arbitrary values.

---

## Common follow-up questions

- What happens to your results if `username` in `users` contains trailing whitespace or mixed casing? _(Tests awareness of text normalization issues that silently fragment GROUP BY results.)_
- If `users` and `transactions` have a one-to-many relationship, how does that affect the COUNT in your GROUP BY? _(Tests understanding of fan-out: joining before grouping can inflate counts.)_
- `user_id` in `users` has ~20M distinct values. What index strategy keeps your query from doing a full table scan? _(Tests whether the candidate can design indexes for high-cardinality columns and understands selectivity.)_
- Could you express this same logic as a single query without CTEs or subqueries? What readability trade-off does that introduce? _(Tests whether the candidate can flatten nested logic and understands when decomposition aids maintainability.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/active_users_with_april_transactions)
- [SQL Interview Questions](https://datadriven.io/sql-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.