bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1327. List the Products Ordered in a Period

1327. List the Products Ordered in a Period

Leetcode Solutions

Joining Tables and Aggregating Conditionally

  1. Join the Products table with the Orders table on the product_id column.
  2. Filter the orders to include only those with an order_date in February 2020.
  3. Group the results by product_id (and product_name to include it in the final result).
  4. Sum the unit column to get the total units ordered for each product.
  5. Use the HAVING clause to filter the groups to only include those with a sum of units greater than or equal to 100.
  6. Select the product_name and the sum of unit as the final output.

erDiagram
    Products {
        int product_id PK
        varchar product_name
        varchar product_category
    }

    Orders {
        int product_id FK
        date order_date
        int unit
    }

    Products ||--o{ Orders : contains

Using Subquery for Conditional Aggregation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...