Skip to main content
Back to problems
Leetcode
Medium
Arrays
Hash Maps
Strings
List The Products Ordered in a Period

Find products that were ordered within a given date range and meet the required ordering threshold.

Acceptance 0%
Problem Statement

You are given order records containing product purchases and the date of each order. Write a query that returns the products ordered in a specified period, along with the number of times each product was ordered.

Only include products that satisfy the problem's filtering rules for the target period, and present the results in the required sorted order.

Input Format

  • A table of order records with at least product and order-date fields.
  • A date range is used to define the period of interest.
  • Each row represents one ordered product instance.

Output Format

Return the qualifying products with their order counts for the requested period, ordered according to the problem requirements.

Constraints

  • Dates are valid and comparable.
  • Multiple orders may exist for the same product.
  • The result should contain only products matching the period filter and aggregation condition.
  • Use the required sort order from the query specification.
Examples
Sample cases returned by the problem API.

Example 1

Input

Orders
+------------+------------+
| product    | order_date |
+------------+------------+
| keyboard   | 2020-01-01 |
| mouse      | 2020-01-02 |
| keyboard   | 2020-01-03 |
| monitor    | 2020-02-01 |
+------------+------------+
Period: 2020-01-01 to 2020-01-31

Output

+------------+-------+
| product    | count |
+------------+-------+
| keyboard   | 2     |
| mouse      | 1     |
+------------+-------+

Explanation

Only orders inside the January range are counted. Keyboard appears twice and mouse once.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.