AnalystPath

Running Total of Donations per Donor

SQLMediumMid level~15 min

Problem

A charity records each donation a supporter makes on a given date.

Table: `gifts`

| Column | Type |
|-------------|------|
| donor_id | int |
| campaign_id | int |
| gift_date | date |
| amount | int |

`(donor_id, gift_date)` is the primary key.

Write a query that reports, for each donor and each of their gift dates, the **cumulative total** the donor has given up to and including that date. Return columns `donor_id`, `gift_date`, and `total_so_far`, in any order.

Tables

Example rows — the live problem includes the full dataset.

gifts
donor_idcampaign_idgift_dateamount
122019-03-015
122019-05-026
132020-06-251

Expected output

Your answer should return 5 rows with the columns donor_id, gift_date, total_so_far.

Starter code (SQL)

SELECT *
FROM gifts;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions