+-----------------+----------+
|Column Name |Type|+-----------------+----------+
| order_number | int || customer_number | int |+-----------------+----------+
order_number is the primarykeyfor this table.
This tablecontains information about the order ID and the customer ID.
Write an SQL query to find the customer_number for the customer who has placed the largest number of orders.
The test cases are generated so that exactly one customer will have placed more orders than any other customer.
Explanation:
The customer with number 3 has two orders, which is greater than either customer 1 or 2 because each of them only has one order.
So the result is customer_number 3.
SELECT customer_number
FROM orders
GROUPBY customer_number
HAVINGCOUNT(order_number) = (
SELECTCOUNT(order_number) cnt
FROM orders
GROUPBY customer_number
ORDERBY cnt DESCLIMIT1)
1
2
3
4
5
6
7
8
9
10
import pandas as pd
deflargest_orders(orders: pd.DataFrame) -> pd.DataFrame:
# Group by customer_number and count the number of orders for each customer customer_order_counts = orders.groupby('customer_number')['order_number'].count().reset_index()
# Find the customer with the largest number of orders max_orders_customer = customer_order_counts[customer_order_counts['order_number'] == customer_order_counts['order_number'].max()][['customer_number']]
return max_orders_customer