-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomer Placing the Largest Number Orders 8-10-22
More file actions
53 lines (34 loc) · 1.41 KB
/
Customer Placing the Largest Number Orders 8-10-22
File metadata and controls
53 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
link ----- https://www.codingninjas.com/codestudio/problems/customer-placing-the-largest-number-of-orders_2111951?topList=top-100-sql-problems
Problem Statement
Table: Orders
+-----------------+----------+
| Column Name | Type |
+-----------------+----------+
| order_number | int |
| customer_number | int |
+-----------------+----------+
order_number is the primary key for this table.
This table contains 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.
It is guaranteed that exactly one customer will have placed more orders than any other customer.
The query result format is in the following example:
Orders table:
+--------------+-----------------+
| order_number | customer_number |
+--------------+-----------------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 3 |
+--------------+-----------------+
Result table:
+-----------------+
| customer_number |
+-----------------+
| 3 |
+-----------------+
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.
----------------------- solution ---------------------
select customer_number from
Orders group by 1 limit 1