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
8 changes: 8 additions & 0 deletions Number_of_passengers_in_each_bus.SQL
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 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
where p.arrival_time <= b.arrival_time
group by p.passenger_id)

select b.bus_id, count(c.btime) As passengers_cnt from buses b left join CTE C on b.arrival_time = c.btime
group by b.bus_id order by b.bus_id
10 changes: 10 additions & 0 deletions User_Activity.SQL
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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-27' and activity_date <= '2019-07-27'
# group by 1;
# select activity_date as 'day', Count(Distinct user_id) As 'active_users'
# from Activity where DATEDIFF('2019-07-27', activity_date) >= 0 AND DATEDIFF('2019-07-#27',activity_date) < 30
# group by 1;
select activity_date as 'day', Count(Distinct user_id) As 'active_users'
from Activity where activity_date between DATE_SUB('2019-07-27', Interval 29 DAY) AND '2019-07-27'
group by 1;
6 changes: 6 additions & 0 deletions consecutive_numbers.SQL
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 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