You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|1384|[Total Sales Amount by Year](https://leetcode.com/problems/total-sales-amount-by-year/)|[Solution](../master/database/_1384.sql)|| Hard |
944
945
|1378|[Replace Employee ID With The Unique Identifier](https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/)|[Solution](../master/database/_1378.sql)|| Easy |
945
946
|1369|[Get the Second Most Recent Activity](https://leetcode.com/problems/get-the-second-most-recent-activity/)|[Solution](../master/database/_1369.sql)|| Hard |
--city_id is the id of the city who bought the product "product_name".
26
+
--
27
+
--
28
+
--Write an SQL query to report the distance travelled by each user.
29
+
--
30
+
--Return the result table ordered by travelled_distance in descending order, if two or more users travelled the same distance, order them by their name in ascending order.
31
+
--
32
+
--The query result format is in the following example.
33
+
--
34
+
--Users table:
35
+
--+------+-----------+
36
+
--| id | name |
37
+
--+------+-----------+
38
+
--| 1 | Alice |
39
+
--| 2 | Bob |
40
+
--| 3 | Alex |
41
+
--| 4 | Donald |
42
+
--| 7 | Lee |
43
+
--| 13 | Jonathan |
44
+
--| 19 | Elvis |
45
+
--+------+-----------+
46
+
--
47
+
--Rides table:
48
+
--+------+----------+----------+
49
+
--| id | user_id | distance |
50
+
--+------+----------+----------+
51
+
--| 1 | 1 | 120 |
52
+
--| 2 | 2 | 317 |
53
+
--| 3 | 3 | 222 |
54
+
--| 4 | 7 | 100 |
55
+
--| 5 | 13 | 312 |
56
+
--| 6 | 19 | 50 |
57
+
--| 7 | 7 | 120 |
58
+
--| 8 | 19 | 400 |
59
+
--| 9 | 7 | 230 |
60
+
--+------+----------+----------+
61
+
--
62
+
--Result table:
63
+
--+----------+--------------------+
64
+
--| name | travelled_distance |
65
+
--+----------+--------------------+
66
+
--| Elvis | 450 |
67
+
--| Lee | 450 |
68
+
--| Bob | 317 |
69
+
--| Jonathan | 312 |
70
+
--| Alex | 222 |
71
+
--| Alice | 120 |
72
+
--| Donald | 0 |
73
+
--+----------+--------------------+
74
+
--Elvis and Lee travelled 450 miles, Elvis is the top traveller as his name is alphabetically smaller than Lee.
75
+
--Bob, Jonathan, Alex and Alice have only one ride and we just order them by the total distances of the ride.
76
+
--Donald didn't have any rides, the distance travelled by him is 0.
0 commit comments