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
9 changes: 9 additions & 0 deletions Problem1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Write your MySQL query statement below
select distinct(num) as consecutiveNums
from (
select id,num,
lag(num) over(order by id) as pervious_num,
lead(num) over(order by id) as next_num
from logs
) sq
where sq.num=sq.pervious_num and sq.num=sq.next_num;
10 changes: 10 additions & 0 deletions Problem2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT b.id AS bus_id, COUNT(p.passenger_id) AS passengers_cnt
FROM Buses b
LEFT JOIN (
SELECT p.passenger_id, MIN(b.id) AS bb
FROM Passengers p
JOIN Buses b ON p.arrival_time <= b.arrival_time
GROUP BY p.passenger_id
) AS p ON b.id = p.bb
GROUP BY b.id
ORDER BY b.id;
Empty file added Problem4.sql
Empty file.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sql3

1 Problem 1 : Consecutive Numbers (https://leetcode.com/problems/consecutive-numbers/)
Problem 1 : Consecutive Numbers (https://leetcode.com/problems/consecutive-numbers/)

2 Problem 2 :Number of Passengers in Each Bus ( https://leetcode.com/problems/the-number-of-passengers-in-each-bus-i/ )

Expand Down
6 changes: 6 additions & 0 deletions problem3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Write your MySQL query statement below
select activity_date as day,count(DISTINCT user_id) as active_users
from Activity
where datediff('2019-07-27',activity_date) <30
and activity_date <= '2019-07-27'
group by activity_date;