Cumulative Sales Since Last Restocking

Start Timer

0:00:00

Upvote
7
Downvote
Save question
Mark as completed
View comments (19)

As an accountant for a local grocery store, you have been tasked with calculating the daily sales of each product since their last restocking.

You have been provided with three tables: products, sales, and restocking. The products table contains information about each product, the sales table records the sales transactions, and the restocking table tracks the restocking events.

Write a query to retrieve the running total of sales for each product since its last restocking event.

Notes: The sales_since_last_restock column represents the cumulative sales of the product for each day since its last restocking event. Order the result set by product_id.

Example:

Input:

Table products:

Column Type
product_id int
product_name varchar

Table sales:

Column Type
sales_id int
product_id int
date date
sold_count int

Table restocking:

Column Type
restock_id int
product_id int
restock_date date

Output

Column Type
product_name varchar
date date
sales_since_last_restock int
.
.
.
.
.


Comments

Loading comments