Table: orders
+--------------+---------+ | Column Name | Type | +--------------+---------+ | order_id | int | | customer_id | int | | restaurant_id| int | | order_date | date | | order_amount | float | +--------------+---------+
order_idis the primary key. Each row represents one order placed by a customer.
For each month, return the single top-order-count customer who is not high-frequency (high-frequency = more than 30 orders in that month). Break ties by customer_id ascending. Months where every customer is high-frequency produce no row in the output.
Output: month (YYYY-MM), customer_id, order_count. One row per month, sorted by month ascending.
The result format is shown below.
Example
Input:
orders table (abbreviated): +----------+-------------+---------------+------------+--------------+ | order_id | customer_id | restaurant_id | order_date | order_amount | +----------+-------------+---------------+------------+--------------+ | 1..35 | 1 | 10 | 2021-01-01 | 10.0 | (35 orders, high-frequency, excluded) | 36..60 | 2 | 10 | 2021-01-01 | 10.0 | (25 orders) | 61..70 | 3 | 10 | 2021-01-01 | 10.0 | (10 orders) +----------+-------------+---------------+------------+--------------+Output:
+---------+-------------+-------------+ | month | customer_id | order_count | +---------+-------------+-------------+ | 2021-01 | 2 | 25 | +---------+-------------+-------------+Explanation:
C1 is excluded (35 > 30). Among the remaining customers, C2 has the most orders (25) and is returned.
Accepted
39/157
Acceptance Rate24.8%
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
-
Output
-
Expected
-