Skip to content

Practice Seasonal Sales Analysis

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3564
LeetCode Problem

Seasonal Sales Analysis

Problem Statement

Tables: sales(sale_id INT, product_id INT, sale_date DATE, quantity INT, price DECIMAL) and products(product_id INT, product_name VARCHAR, category VARCHAR). Group sales into Winter (December-February), Spring (March-May), Summer (June-August), and Fall (September-November), across recorded years. In each season choose the category with greatest total quantity, then greatest sum of quantity times sale price, then lexicographically smallest category. Return season, category, total_quantity, and total_revenue, ordered by season ascending. Practice approach: Map months to seasons, aggregate category totals, then rank each season by all three tie-breakers. Revenue uses the price on each sale. Alphabetical season order is different from calendar order.

Source: Seasonal Sales Analysis on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
{
  "products": [
    {
      "product_id": 1,
      "product_name": "Pen",
      "category": "Art"
    },
    {
      "product_id": 2,
      "product_name": "Puzzle",
      "category": "Games"
    }
  ],
  "sales": [
    {
      "sale_id": 1,
      "product_id": 1,
      "sale_date": "2026-03-01",
      "quantity": 2,
      "price": 4
    },
    {
      "sale_id": 2,
      "product_id": 2,
      "sale_date": "2026-04-01",
      "quantity": 2,
      "price": 5
    },
    {
      "sale_id": 3,
      "product_id": 1,
      "sale_date": "2026-01-01",
      "quantity": 3,
      "price": 2
    },
    {
      "sale_id": 4,
      "product_id": 2,
      "sale_date": "2025-12-01",
      "quantity": 3,
      "price": 2
    }
  ]
}
Output
[
  {
    "season": "Spring",
    "category": "Games",
    "total_quantity": 2,
    "total_revenue": 10
  },
  {
    "season": "Winter",
    "category": "Art",
    "total_quantity": 3,
    "total_revenue": 6
  }
]
Explanation

Spring uses revenue to break equal quantities. Winter ties on quantity and revenue, so Art wins alphabetically.

Constraints

sales has key sale_id; products has key product_id.
Final ties use category ascending.

Related LeetCode Problems

Practice more problems similar to Seasonal Sales Analysis.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.