# Highest Daily Spend

> Somewhere in that window, someone broke the spending record.

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

Domain: SQL · Difficulty: medium · Seniority: L4

## Problem

Between March 1 and June 1, 2026, find the users with the highest daily spending. If a user placed multiple orders on the same day, sum those amounts. If multiple users tie for the highest daily total on a given date, return all of them. Every username is unique.

## Worked solution and explanation

### Why this problem exists in real interviews

Finding users with the highest daily spend tests date truncation, aggregation, and top-N filtering. The prompt specifies a date range (March to June), adds per-user daily aggregation, and asks for the highest spenders.

---

### Break down the requirements

#### Step 1: Filter to the date range

`WHERE transaction_date >= '2026-03-01' AND transaction_date < '2026-06-01'` scopes to the target period.

#### Step 2: Aggregate per user per day

`GROUP BY user_id, DATE(transaction_date)` with `SUM(total_amount)` gives daily spend per user.

#### Step 3: Rank by daily spend

Order by daily spend descending to find the highest single-day spenders.

---

### The solution

**Date-filtered per-user daily spend aggregation**

```sql
SELECT u.user_id, u.username,
       DATE(t.transaction_date) AS spend_date,
       ROUND(SUM(t.total_amount), 2) AS daily_spend
FROM transactions t
JOIN users u ON t.user_id = u.user_id
WHERE t.transaction_date >= '2026-03-01'
  AND t.transaction_date < '2026-06-01'
GROUP BY u.user_id, u.username, DATE(t.transaction_date)
ORDER BY daily_spend DESC
```

> **Cost Analysis**
>
> The date range filter reduces the working set. An index on `transactions(transaction_date, user_id)` is optimal.

> **Interviewers Watch For**
>
> The interviewer checks that you aggregate to per-user-per-day grain, not just per-user total.

> **Common Pitfall**
>
> Finding MAX(total_amount) gives the largest single transaction, not the highest daily total.

---

## Common follow-up questions

- How would you return only the top 5 user-day combinations? _(Tests adding LIMIT 5.)_
- What if ties exist for the highest daily spend? _(Tests DENSE_RANK instead of LIMIT.)_
- How would you show each user's highest spending day only? _(Tests ROW_NUMBER PARTITION BY user_id.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/highest_daily_spend)
- [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.