# Weekly Transaction Volume

> Weekly volume. The pulse.

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

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

For Q1 2026, calculate total transaction quantity per week (starting Sunday). Show the week start date and total quantity.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests date truncation combined with a date range filter and aggregation. Interviewers check whether you can compute weekly buckets starting on Sunday and filter to a specific quarter.

---

### Break down the requirements

#### Step 1: Filter to Q1

`WHERE transaction_date >= '2026-01-01' AND transaction_date < '2026-04-01'` captures all Q1 transactions.

#### Step 2: Truncate to week starting Sunday

`DATE(transaction_date, 'weekday 0', '-7 days')` computes the Sunday start of each week.

#### Step 3: Sum quantity per week

`GROUP BY week_start` with `SUM(quantity)` produces the weekly total quantity.

---

### The solution

**Weekly aggregation with Sunday-start bucketing**

```sql
SELECT
    DATE(transaction_date, 'weekday 0', '-7 days') AS week_start,
    SUM(quantity) AS total_quantity
FROM transactions
WHERE transaction_date >= '2026-01-01'
  AND transaction_date < '2026-04-01'
GROUP BY week_start
ORDER BY week_start
```

> **Cost Analysis**
>
> The date filter narrows 60M rows to ~15M (Q1 is 3 of 12 months). The GROUP BY produces ~13 weekly buckets. An index on `transaction_date` enables an efficient range scan.

> **Interviewers Watch For**
>
> Correct handling of partial weeks at the quarter boundaries. The first and last weeks of Q1 may be partial, but the query handles this naturally by grouping by the Sunday start.

> **Common Pitfall**
>
> Using `STRFTIME('%W', ...)` which returns the ISO week number. This groups by week number but does not give you the actual week start date for display.

---

## Common follow-up questions

- How would you compute week-over-week growth? _(Use LAG on the weekly totals: current_week - LAG(total_quantity) OVER (ORDER BY week_start).)_
- What if you needed daily granularity instead of weekly? _(Remove the date truncation and GROUP BY transaction_date directly.)_
- How would you handle weeks that span the quarter boundary? _(The date filter truncates mid-week; discuss whether to include or exclude partial weeks.)_

## Related

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