Problem · Medium · 25 min
Running total per store
- Medium
- Window functions
A chain keeps the sales of its stores in the table sales.
| Column | Meaning |
|---|---|
id |
The number of the sale. It is unique. |
store |
The name of the store. |
sold_on |
The day of the sale, as text in the form 2024-05-31. |
amount |
The amount of the sale, as a whole number. It can be negative for a refund. |
Write one query that returns one row for each sale, with these columns:
store,sold_onandamount, as in the table.running_total: the sum ofamountfor all sales of the same store, from the first day up to and including the day of this sale.
Sales of the same store on the same day all show the same running_total: the total at the end of that day.
Sort the rows by store, then by sold_on, then by id.
Tasks
2 to do
Task 1, not checked yet. Return the right rows for the example data.
Task 2, not checked yet. Return the right rows for other data that you cannot see.
Task 1 of 2
Return the right rows for the example data.