Skip to content

Commit 894f4a2

Browse files
authored
Create number-of-times-a-driver-was-a-passenger.sql
1 parent e6f5940 commit 894f4a2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
SELECT d.driver_id,
5+
COUNT(r2.passenger_id) AS cnt
6+
FROM (SELECT DISTINCT r1.driver_id FROM Rides r1) d
7+
LEFT JOIN Rides r2 ON d.driver_id = r2.passenger_id
8+
GROUP BY d.driver_id
9+
ORDER BY NULL;

0 commit comments

Comments
 (0)