Practice

Problem 6 of 8

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_on and amount, as in the table.
  • running_total: the sum of amount for 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

  1. Task 1, not checked yet. Return the right rows for the example data.

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

All tasks

query.sql

Ctrl+Enter runs your code. Ctrl+Shift+Enter runs all the tests. Press Esc, then Tab, to leave the editor.

Output

Press Run to see your result

Your output shows here. Press Run to try your code.