LEETCODE - Passenger Bus Problem - SQL Interview Query 23| SQL Problem Level "HARD"

  Рет қаралды 8,344

techTFQ

techTFQ

Күн бұрын

Пікірлер: 23
@vikaskumar-qr5tj
@vikaskumar-qr5tj 9 ай бұрын
Nice way of approaching the problem and one very good use case of recursive cte..
@Szwagier-fr7ry
@Szwagier-fr7ry 10 ай бұрын
:O Brain blow, thanks to this video I saw for the first time in my life Recursive function in SQL. Love it - thanks!
@theLowestPointInMyLife
@theLowestPointInMyLife 10 ай бұрын
reason for that is you would never need it irl, this is just a stupid made up problem
@SanjayKumar-sr5ft
@SanjayKumar-sr5ft 9 ай бұрын
@@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
@pralaysangma8019
@pralaysangma8019 10 ай бұрын
I learnt many things from your videos on SQL Server. Thank you Taufiq.
@ajinkyatrimukhe
@ajinkyatrimukhe 10 ай бұрын
Mind blown
@Rameshkumar-dk8me
@Rameshkumar-dk8me 10 ай бұрын
Thanks Thoufig with nice problem, please explain the subtraction logic in detail[logic part] .
@balukrishna2581
@balukrishna2581 10 ай бұрын
Please explain a queries related to mutual funds and stocks in this 30 days challenge.
@Ri9t_gaming
@Ri9t_gaming 9 ай бұрын
Is there a way to check which passengers onboarded which bus? or can there be another case where single bus arrives multiple times.
@Tusharchitrakar
@Tusharchitrakar 10 ай бұрын
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
@eniolaabolade8638
@eniolaabolade8638 10 ай бұрын
Hi, can you please post more EDA projects using Python. I love your content 🥺
@akashchristopher
@akashchristopher 10 ай бұрын
should i expect these kind of problems from top tech companie's interviews ?
@fathimafarahna2633
@fathimafarahna2633 10 ай бұрын
🔥🔥🔥
@firojahmed785
@firojahmed785 7 ай бұрын
Hello, I tried to run your MSSQL query, but it shows no rows. Is there something I am missing?
@tanujreddy8597
@tanujreddy8597 4 ай бұрын
should i expect these kind of problems from top tech companie's interviews for freshers?
@muhammadabbas6645
@muhammadabbas6645 10 ай бұрын
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
@techTFQ
@techTFQ 10 ай бұрын
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
@MaciejGozdur
@MaciejGozdur 8 ай бұрын
18.49 how did you get the column total_onboarded_bus? you named two columns onboarded_bus yet they are displayed with different names
@shubhamsom
@shubhamsom 7 ай бұрын
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
@tanmaykumar3250
@tanmaykumar3250 4 ай бұрын
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;
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Querying 100 Billion Rows using SQL, 7 TB in a single table
9:07
Arpit Agrawal (Elastiq.AI)
Рет қаралды 58 М.
LeetCode 1581: Customer Who Visited but Did Not Make Any Transactions [SQL]
11:52
6 SQL Joins you MUST know! (Animated + Practice)
9:47
Anton Putra
Рет қаралды 242 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19