2022-03-27 20:37:52 +08:00
|
|
|
|
<p>表:<code>Users</code></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
+---------------+---------+
|
|
|
|
|
| Column Name | Type |
|
|
|
|
|
+---------------+---------+
|
|
|
|
|
| id | int |
|
|
|
|
|
| name | varchar |
|
|
|
|
|
+---------------+---------+
|
2023-12-09 18:42:21 +08:00
|
|
|
|
id 是该表中具有唯一值的列。
|
2022-03-27 20:37:52 +08:00
|
|
|
|
name 是用户名字。</pre>
|
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p> </p>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
|
|
|
|
|
<p>表:<code>Rides</code></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
+---------------+---------+
|
|
|
|
|
| Column Name | Type |
|
|
|
|
|
+---------------+---------+
|
|
|
|
|
| id | int |
|
|
|
|
|
| user_id | int |
|
|
|
|
|
| distance | int |
|
|
|
|
|
+---------------+---------+
|
2023-12-09 18:42:21 +08:00
|
|
|
|
id 是该表中具有唯一值的列。
|
2022-03-27 20:37:52 +08:00
|
|
|
|
user_id 是本次行程的用户的 id, 而该用户此次行程距离为 distance 。
|
|
|
|
|
</pre>
|
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p> </p>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p>编写解决方案,报告每个用户的旅行距离。</p>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p>返回的结果表单,以 <code>travelled_distance</code> <strong>降序排列</strong> ,如果有两个或者更多的用户旅行了相同的距离, 那么再以 <code>name</code> <strong>升序排列</strong> 。</p>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p>返回结果格式如下例所示。</p>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>示例 1:</strong></p>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
|
|
|
|
|
<pre>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输入:</strong>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
Users 表:
|
|
|
|
|
+------+-----------+
|
|
|
|
|
| id | name |
|
|
|
|
|
+------+-----------+
|
|
|
|
|
| 1 | Alice |
|
|
|
|
|
| 2 | Bob |
|
|
|
|
|
| 3 | Alex |
|
|
|
|
|
| 4 | Donald |
|
|
|
|
|
| 7 | Lee |
|
|
|
|
|
| 13 | Jonathan |
|
|
|
|
|
| 19 | Elvis |
|
|
|
|
|
+------+-----------+
|
|
|
|
|
|
|
|
|
|
Rides 表:
|
|
|
|
|
+------+----------+----------+
|
|
|
|
|
| id | user_id | distance |
|
|
|
|
|
+------+----------+----------+
|
|
|
|
|
| 1 | 1 | 120 |
|
|
|
|
|
| 2 | 2 | 317 |
|
|
|
|
|
| 3 | 3 | 222 |
|
|
|
|
|
| 4 | 7 | 100 |
|
|
|
|
|
| 5 | 13 | 312 |
|
|
|
|
|
| 6 | 19 | 50 |
|
|
|
|
|
| 7 | 7 | 120 |
|
|
|
|
|
| 8 | 19 | 400 |
|
|
|
|
|
| 9 | 7 | 230 |
|
|
|
|
|
+------+----------+----------+
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输出:</strong>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
+----------+--------------------+
|
|
|
|
|
| name | travelled_distance |
|
|
|
|
|
+----------+--------------------+
|
|
|
|
|
| Elvis | 450 |
|
|
|
|
|
| Lee | 450 |
|
|
|
|
|
| Bob | 317 |
|
|
|
|
|
| Jonathan | 312 |
|
|
|
|
|
| Alex | 222 |
|
|
|
|
|
| Alice | 120 |
|
|
|
|
|
| Donald | 0 |
|
|
|
|
|
+----------+--------------------+
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>解释:</strong>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
Elvis 和 Lee 旅行了 450 英里,Elvis 是排名靠前的旅行者,因为他的名字在字母表上的排序比 Lee 更小。
|
|
|
|
|
Bob, Jonathan, Alex 和 Alice 只有一次行程,我们只按此次行程的全部距离对他们排序。
|
|
|
|
|
Donald 没有任何行程, 他的旅行距离为 0。
|
|
|
|
|
</pre>
|