Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Problem1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Write your MySQL query statement below
SELECT DISTINCT l1.num AS 'ConsecutiveNums'
FROM Logs l1, logs l2, Logs l3
WHERE l1.id = l2.id - 1
AND l2.id = l3.id - 1
AND l1.num = l2.num
AND l2.num = l3.num;
14 changes: 14 additions & 0 deletions Problem2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Write your MySQL query statement below
WITH CTE AS (
SELECT p.passenger_id, p.arrival_time, MIN(b.arrival_time) AS 'btime'
FROM Passengers p
INNER JOIN Buses b
ON p.arrival_time <= b.arrival_time
GROUP BY passenger_id
)
SELECT b.bus_id, COUNT(c.btime) AS 'passengers_cnt'
FROM Buses b
LEFT JOIN CTE c
ON c.btime = b.arrival_time
GROUP BY b.bus_id
ORDER BY b.bus_id;
5 changes: 5 additions & 0 deletions Problem3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Write your MySQL query statement below
SELECT activity_date AS 'day', COUNT(DISTINCT user_id) AS 'active_users'
FROM Activity
WHERE activity_date >= '2019-06-28' AND activity_date <= '2019-07-27'
GROUP BY activity_date;