Skip to content

Commit 1498e84

Browse files
committed
Upload 171
1 parent db4e530 commit 1498e84

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- markdownlint-disable MD041 -->
22
[![eevveerryyddaayy release](https://img.shields.io/badge/eevveerryyddaayy-v1.3.0-blue.svg)](https://github.com/ggeerraarrdd/eevveerryyddaayy/)
3-
[![Solved](https://img.shields.io/badge/solved-170-green.svg)](#index)
3+
[![Solved](https://img.shields.io/badge/solved-171-green.svg)](#index)
44
<!-- markdownlint-enable MD041 -->
55

66
# SQL Everyday
@@ -204,6 +204,7 @@ Because this project necessitated a framework to enable consistent daily practic
204204
| 168 | [SQL Basics: Simple UNION ALL](https://www.codewars.com/kata/58112f8004adbbdb500004fe/sql) | [Solution](solutions/168_sql_basics_simple_union_all.md) | Codewars | Medium | |
205205
| 169 | [NPV Queries](https://leetcode.com/problems/npv-queries/description/) | [Solution](solutions/169_npv_queries.md) | LeetCode | Easy | |
206206
| 170 | [Game Play Analysis II](https://leetcode.com/problems/game-play-analysis-ii/description/) | [Solution](solutions/170_game_play_analysis_ii.md) | LeetCode | Easy | |
207+
| 171 | [Total Traveled Distance](https://leetcode.com/problems/total-traveled-distance/description/) | [Solution](solutions/171_total_traveled_distance.md) | LeetCode | Easy | |
207208
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
208209
<!--- cSpell:enable --->
209210

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SQL Everyday \#171
2+
3+
## Total Traveled Distance
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Easy
7+
8+
## Problem
9+
10+
Write a solution to calculate the `distance` traveled by *each user*. If there is a user who hasn't completed any rides, then their distance should be considered as `0`. Output the `user_id`, `name` and total traveled `distance`.
11+
12+
Return the result table ordered by `user_id` in *ascending order*. [[Full Description](https://leetcode.com/problems/total-traveled-distance/description/)]
13+
14+
## Submitted Solution
15+
16+
```sql
17+
-- Submitted Solution
18+
SELECT
19+
u.user_id
20+
,u.name
21+
,COALESCE(SUM(r.distance), 0) AS "traveled distance"
22+
FROM Users AS u
23+
LEFT JOIN Rides AS r ON u.user_id = r.user_id
24+
GROUP BY u.user_id, u.name
25+
ORDER BY u.user_id ASC
26+
;
27+
```
28+
29+
## Site Solution
30+
31+
```sql
32+
-- LeetCode Solution
33+
SELECT u.user_id,
34+
u.name,
35+
IFNULL(SUM(distance), 0) AS 'traveled distance'
36+
FROM Users AS u
37+
LEFT JOIN Rides AS r
38+
ON u.user_id = r.user_id
39+
GROUP BY user_id, name
40+
ORDER BY user_id
41+
```
42+
43+
## Notes
44+
45+
TBD
46+
47+
## NB
48+
49+
TBD
50+
51+
Go to [Index](../?tab=readme-ov-file#index)\
52+
Go to [Overview](../?tab=readme-ov-file)

0 commit comments

Comments
 (0)