diff --git a/Number_of_passengers_in_each_bus.SQL b/Number_of_passengers_in_each_bus.SQL new file mode 100644 index 0000000..f03715c --- /dev/null +++ b/Number_of_passengers_in_each_bus.SQL @@ -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 \ No newline at end of file diff --git a/User_Activity.SQL b/User_Activity.SQL new file mode 100644 index 0000000..5ee8662 --- /dev/null +++ b/User_Activity.SQL @@ -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; \ No newline at end of file diff --git a/consecutive_numbers.SQL b/consecutive_numbers.SQL new file mode 100644 index 0000000..83b2c42 --- /dev/null +++ b/consecutive_numbers.SQL @@ -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 \ No newline at end of file