Seasonal Product Performance Analysis

Start Timer

0:00:00

Upvote
0
Downvote
Save question
Mark as completed
View comments (1)

Walmart is analyzing how product performance changes across American seasons: Spring, Summer, Fall, Winter. The company stores sales records and seasonal product assignments in separate tables. A product may belong to different seasonal collections in different years.

Write a SQL query to compute the total revenue for each (season, year) pair by joining the two tables on multiple columns. Your final output should include season, year and total_revenue (rounded to 2 decimals)

Sort results by year ascending, then by season order: Spring → Summer → Fall → Winter.

Notes

  • The join must match on product_id AND year.
  • Seasonal assignment varies by year.
  • Revenue is computed from: quantity * price
  • Every season/year combination appearing in the data must be included.

Schema

Input

seasonal_products table

Column Type
product_id INTEGER
season VARCHAR
year INTEGER

sales table

Column Type
sale_id INTEGER
product_id INTEGER
year INTEGER
quantity INTEGER
price DECIMAL

Output

Column Type
season VARCHAR
year INTEGER
total_revenue DECIMAL

Example

Input

seasonal_products table

product_id season year
10 Spring 2024
10 Summer 2024
20 Fall 2024
30 Winter 2024

sales table

sale_id product_id year quantity price
1 10 2024 2 50
2 10 2024 1 40
3 20 2024 3 30
4 30 2024 1 100

Output

season year total_revenue
Spring 2024 140.00
Summer 2024 140.00
Fall 2024 90.00
Winter 2024 100.00

Explanation

In Spring 2024, product 10 appears with total sales of (2 × 50) + (1 × 40) = 140. In Summer 2024, the same product is assigned to a different season within the same year, so its total is again 140. In Fall 2024, only product 20 appears, giving 3 × 30 = 90. In Winter 2024, only product 30 appears with 1 × 100 = 100.

The key detail:

A product may appear in multiple seasons in the same year, but JOIN must match both the product_id and year, ensuring that seasonal assignment is year-specific.

.
.
.
.
.


Comments

Loading comments