Leetcode Problem 1565. Unique Orders and Customers Per Month

1565. Unique Orders and Customers Per Month

Leetcode Solutions

Grouping by Month and Aggregating Unique Orders and Customers

  1. Select the year and month from the order_date column.
  2. Use a WHERE clause to filter out orders with invoice less than or equal to 20.
  3. Group the results by the extracted year and month.
  4. Count the distinct order_id to get the number of unique orders for each month.
  5. Count the distinct customer_id to get the number of unique customers for each month.
  6. Return the results with the columns month, order_count, and customer_count.

erDiagram
    Orders {
        int order_id PK "Unique order identifier"
        date order_date "Date when the order was placed"
        int customer_id "Identifier of the customer who made the order"
        int invoice "Total invoice amount for the order"
    }

Using DATE_FORMAT to Group by Month and Aggregate Unique Orders and Customers

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...