Interview Query

Monthly Product Sales

1
Have you seen this question before?

Given a table containing data for monthly sales, write a query to find the total amount of each product sold for each month with each product as its own column in the output table.

Example:

Input:

monthly_sales table

month product_id amount_sold
2021-01-01 1 100
2021-01-01 2 300
2021-02-01 3 200
2021-03-01 4 250

Output:

month 1 2 3 4
2021-01-01 100 0 300 0
2021-02-01 0 200 0 0
2021-03-01 0 0 0 250
Next question: Distance Traveled
.....
MySQL 8.0.17
Loading editor
Use Shift + Enter to run query