Загрузка...

தமிழில் - Coding Series - SQL : Last Person to Fit in the Bus #sqlfordataengineer #sqlinterview

Crack SQL Interview in 50 Questions - Q35 (தமிழில்):
Last Person to Fit in the Bus

Video: https://www.youtube.com/watch?v=Fomt950qJOs

Video 144: This is the 35th video in our series "Crack SQL Interview in 50 Questions," and in this exercise, we explore the topic of "Advanced Select and Joins."

In this video, we dive into the realm of SQL queries to solve: finding the last person to fit in the bus.

Given a table called "Queue" with columns for person_id, name, weight and turn. person_id column contains unique values.
This table has the information about all people waiting for a bus.
The person_id and turn columns will contain all numbers from 1 to n, where n is the number of rows in the table.
turn determines the order of which the people will board the bus, where turn=1 denotes the first person to board and turn=n denotes the last person to board. weight is the weight of the person in kilograms.

There is a queue of people waiting to board a bus. However, the bus has a weight limit of 1000 pounds, so there may be some people who cannot board.

Write a solution to find the person_name of the last person that can fit on the bus without exceeding the weight limit. The test cases are generated such that the first person does not exceed the weight limit.

*** Approach 1: Self Join ***
In the first approach, we use a self join to calculate the cumulative weight at each turn. By grouping the results and filtering rows where the cumulative weight is within the limit, we can efficiently identify the last person who can board the bus.

*** Approach 2: Using Windows Function ***
Next, we explore a solution using a window function to compute the cumulative weight. This approach simplifies the query by eliminating the need for explicit joins. We then filter the results based on the weight limit to find the appropriate person.

*** Approach 3: Replace LIMIT with Subquery ***
Finally, we present an alternative solution by replacing the LIMIT function with an additional subquery. This approach ensures that we select the last person whose cumulative weight does not exceed the limit, providing a concise and effective solution.

For a comprehensive understanding of these SQL methodologies and their application, please refer to this explanatory video.

code: https://github.com/jeganpillai/crack_sql_interview_in_50_questions/blob/main/seq01_35_last_person_to_fit_in_the_bus.sql

Follow me on,
Website : https://growwithdata.co/
YouTube : https://www.youtube.com/@growwithdata
TikTok : https://www.tiktok.com/@growwithdata
LinkedIn : https://www.linkedin.com/company/growwithdata/
Facebook : https://www.facebook.com/growwithdata.co/
twitter : https://twitter.com/growwithdata_co
Instagram : https://www.instagram.com/growwithdata.co/
WhatsApp : https://whatsapp.com/channel/0029VaF8pkb77qVNfbp5pA0S

#sql #dataengineers #tablejoins #ceil #floor #bucket #meta #google #facebook #apple #paypal #netflix #amazon #deinterview #sqlinterview #interviewquestions #leetcode #faang #maanga #mysql #oracle #dbms #query #sqlserver #mysql #coderpad #aggregates #aggregation #nonaggregation #database #placementpreparation #lead #lag #windowsfunction #nullcheck #coalesce #sqlperformance #ifnull #case #lead #lag #windowsfunction #tamil #tamilpython #tamilinterview #tamilinterviewlatest #tamilinterviewquestions #sqlintamil

Видео தமிழில் - Coding Series - SQL : Last Person to Fit in the Bus #sqlfordataengineer #sqlinterview канала Grow with Data
Яндекс.Метрика

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять