2022-03-27 20:46:41 +08:00
|
|
|
|
<p>表: <code>Orders</code></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
+-----------------+----------+
|
|
|
|
|
| Column Name | Type |
|
|
|
|
|
+-----------------+----------+
|
|
|
|
|
| order_number | int |
|
|
|
|
|
| customer_number | int |
|
|
|
|
|
+-----------------+----------+
|
2023-12-09 18:42:21 +08:00
|
|
|
|
在 SQL 中,Order_number是该表的主键。
|
2022-03-27 20:46:41 +08:00
|
|
|
|
此表包含关于订单ID和客户ID的信息。
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p>查找下了 <strong>最多订单</strong> 的客户的 <code>customer_number</code> 。</p>
|
2022-03-27 20:46:41 +08:00
|
|
|
|
|
|
|
|
|
<p>测试用例生成后, <strong>恰好有一个客户</strong> 比任何其他客户下了更多的订单。</p>
|
|
|
|
|
|
|
|
|
|
<p>查询结果格式如下所示。</p>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>示例 1:</strong></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
<strong>输入:</strong>
|
|
|
|
|
Orders 表:
|
|
|
|
|
+--------------+-----------------+
|
|
|
|
|
| order_number | customer_number |
|
|
|
|
|
+--------------+-----------------+
|
|
|
|
|
| 1 | 1 |
|
|
|
|
|
| 2 | 2 |
|
|
|
|
|
| 3 | 3 |
|
|
|
|
|
| 4 | 3 |
|
|
|
|
|
+--------------+-----------------+
|
|
|
|
|
<strong>输出:</strong>
|
|
|
|
|
+-----------------+
|
|
|
|
|
| customer_number |
|
|
|
|
|
+-----------------+
|
|
|
|
|
| 3 |
|
|
|
|
|
+-----------------+
|
|
|
|
|
<strong>解释:</strong>
|
|
|
|
|
customer_number 为 '3' 的顾客有两个订单,比顾客 '1' 或者 '2' 都要多,因为他们只有一个订单。
|
|
|
|
|
所以结果是该顾客的 customer_number ,也就是 3 。
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>进阶:</strong> 如果有多位顾客订单数并列最多,你能找到他们所有的 <code>customer_number</code> 吗?</p>
|