Nice way of approaching the problem and one very good use case of recursive cte..
@Szwagier-fr7ry10 ай бұрын
:O Brain blow, thanks to this video I saw for the first time in my life Recursive function in SQL. Love it - thanks!
@theLowestPointInMyLife10 ай бұрын
reason for that is you would never need it irl, this is just a stupid made up problem
@SanjayKumar-sr5ft9 ай бұрын
@@theLowestPointInMyLife yes this may be a madeup question,but this certainly improves how to approach "reccursive" question...i mean how to relate pervious iteration and current iteration,which may be a real scenario
@pralaysangma801910 ай бұрын
I learnt many things from your videos on SQL Server. Thank you Taufiq.
@ajinkyatrimukhe10 ай бұрын
Mind blown
@Rameshkumar-dk8me10 ай бұрын
Thanks Thoufig with nice problem, please explain the subtraction logic in detail[logic part] .
@balukrishna258110 ай бұрын
Please explain a queries related to mutual funds and stocks in this 30 days challenge.
@Ri9t_gaming9 ай бұрын
Is there a way to check which passengers onboarded which bus? or can there be another case where single bus arrives multiple times.
@Tusharchitrakar10 ай бұрын
Thanks for finally uploading this leetcode problem based on our discussion a week back. I have also posted my MySQL solution for others. I have one request for a future video: since you focussed so much on improving the speed of the query, can you make a future video on query optimization techniques and tips? It'll be very very helpful especially from a work point of view where we would be expected to write 200-1000 lines of SQL code. Thanks! -- to join passengers to all possible buses and calculate total passengers possible for each bus -- View is created since a recursive cte cannot access a regular cte in mysql create view max_passengers as ( select bus.bus_id, bus.capacity, count(*) as max_poss from buses as bus join passengers as pass on pass.arrival_time
@eniolaabolade863810 ай бұрын
Hi, can you please post more EDA projects using Python. I love your content 🥺
@akashchristopher10 ай бұрын
should i expect these kind of problems from top tech companie's interviews ?
@fathimafarahna263310 ай бұрын
🔥🔥🔥
@firojahmed7857 ай бұрын
Hello, I tried to run your MSSQL query, but it shows no rows. Is there something I am missing?
@tanujreddy85974 ай бұрын
should i expect these kind of problems from top tech companie's interviews for freshers?
@muhammadabbas664510 ай бұрын
Hello Sir hope you are doing well sorry to disturb you again as after watching this video more than 2 times I an unable to understand why we need total_onboarded_pessangers can you please elaborate as my answer is quite similar with yours but I didnt add total_onboarded_pessangers and got my answer right thanks you for all your videos as it makes me good in sql language God bless you and your family
@techTFQ10 ай бұрын
You need to test your solution with other datasets. I have shared 5 different sample data .. check if your solution works for them .. you will probably then realize why total onboarding field is required
@MaciejGozdur8 ай бұрын
18.49 how did you get the column total_onboarded_bus? you named two columns onboarded_bus yet they are displayed with different names
@shubhamsom7 ай бұрын
columns names displayed are based on what you have written at initialization state of recursion cte , since column-name was onboarded_bus at rn=1, now you might know the reason
@tanmaykumar32504 ай бұрын
this one is without recursive cte using window function. Though using recursive cte looks easier and good approach. But here is my solution : WITH bus AS ( SELECT bus_id, arrival_time, IFNULL(LAG(arrival_time) OVER(ORDER BY arrival_time ASC), 0) AS prev_bus_time, capacity FROM buses ), cte AS ( SELECT b.bus_id, b.arrival_time AS bus_arrival, b.prev_bus_time, b.capacity, p.* FROM bus AS b LEFT JOIN Passengers AS p ON p.arrival_time b.prev_bus_time ORDER BY b.arrival_time ), cte2 AS ( SELECT bus_id, ROUND(AVG(bus_arrival)) AS bus_arrival, ROUND(AVG(capacity)) AS capacity, COUNT(DISTINCT passenger_id) AS passengers FROM cte GROUP BY bus_id ORDER BY ROUND(AVG(bus_arrival)) ), cte3 AS ( SELECT *, IF( passengers - capacity + IF( IFNULL(LAG(passengers) OVER(ORDER BY bus_arrival), 0) - IFNULL(LAG(capacity) OVER(ORDER BY bus_arrival), 0) > 0, IFNULL(LAG(passengers) OVER(ORDER BY bus_arrival), 0) - IFNULL(LAG(capacity) OVER(ORDER BY bus_arrival), 0), 0 ) > 0, passengers - capacity + IF( IFNULL(LAG(passengers) OVER(ORDER BY bus_arrival), 0) - IFNULL(LAG(capacity) OVER(ORDER BY bus_arrival), 0) > 0, IFNULL(LAG(passengers) OVER(ORDER BY bus_arrival), 0) - IFNULL(LAG(capacity) OVER(ORDER BY bus_arrival), 0), 0 ), 0 ) AS passengers_on_platform FROM cte2 ) SELECT bus_id, CASE WHEN capacity >= passengers + IFNULL(LAG(passengers_on_platform) OVER(ORDER BY bus_arrival), 0) THEN passengers + IFNULL(LAG(passengers_on_platform) OVER(ORDER BY bus_arrival), 0) ELSE capacity END AS passengers_in_bus FROM cte3 ORDER BY bus_id;