Hey there! 👋 For more interesting content, tutorials, and updates, Feel free to connect with me on Instagram Handles :- @createwithchirag - instagram.com/createwithchirag/ @learn.with.chirag - instagram.com/learn.with.chirag/ LinkedIn: www.linkedin.com/in/chirag-sehgal-9200111b8/ Let's stay connected and keep the creativity flowing! 💡
@riteshchaudhary87559 ай бұрын
Why do we use > operation in this condition (on q1.turn >= q2.turn)?
@akashsingh27222 ай бұрын
Because we want the last person that exceeds the weight limit to be included in to list as well cuz that's thee guy that'll be the potential "last guy to fit into the bus"
@ARkhan-xw8ud6 ай бұрын
Didn't got it
@learnwithchirag6 ай бұрын
Hi , which part of the solution you aren't able to understand?
@sakshigandhi60596 ай бұрын
@@learnwithchirag can you explain when and why we are taking q1 then we take q2 its confusing to understand that whn do we use q1 or q2
@ARkhan-xw8ud5 ай бұрын
why it returns 3 table instead of 4
@anirudhsinghsolanki62564 ай бұрын
easy method :- select person_name from ( SELECT person_name,turn, sum(weight) over (order by turn) AS weight FROM queue) p where weight
@MuhammadAzeem-he6qr10 ай бұрын
1) Why do we use > operation in this condition (on q1.turn >= q2.turn) 2) Why do we use q2 in sum(q2.weight) , as all weights in q2 are same which is 250 with the same person?
@ayanghosh76927 ай бұрын
I also have the same question. why q2.weight gives the result of q1.weight? if you got answer please reply.
@metatrader1893 ай бұрын
first one to arrange smaller turns in q2 table so that we can sum up later using sum(q2.weight)
@ranitmandal63939 ай бұрын
the solution using window function- select x.person_name from (select turn,person_id,person_name,weight, sum(weight) over(order by turn ) as total_weight from Queue order by turn desc)x where x.total_weight
@raunakkumar95215 ай бұрын
how to know that where i have to used q1 and where i have to used q2 in this question.
@ashish34874 ай бұрын
sir why did we use sum(q2.weight)
@prathamsharma44169 ай бұрын
its accepted on leetcode, but its not running on workbench, why??
@apoorvpradhan51255 ай бұрын
Thank you bhaiya.
@akhilpratapsingh3223 Жыл бұрын
Great Explanation Sir
@learnwithchirag Жыл бұрын
Keep watching :-)
@rey619ashkash10 ай бұрын
With cte as ( select *, sum(weight) over ( order by turn) as w1 from queue) select person_name from cte where w1
@learnwithchirag10 ай бұрын
In terms of efficiency, the query using the CTE and window function is likely to perform better, especially on larger datasets, because it avoids the need for a self-join and calculates the cumulative sum in a single pass through the data. Therefore, the query using the CTE and window function is generally more efficient for this particular task. The purpose of this playlist was to clear the basics and form a strong foundation of SQL amoung people ! Ofcourse the queries can be optimized when writing for a larger database.
@abhinashnayak1006 ай бұрын
select person_name from (SELECT *, sum(weight) over (order by turn) AS sum_w FROM queue) as p1 where sum_w
@nimbu_03 Жыл бұрын
This is easy than previous one for sure :D
@learnwithchirag Жыл бұрын
Yes for sure 🎉
@mohammedsuboorahmed6282Ай бұрын
With cte as (Select *, sum(weight) over (order by turn rows between unbounded preceding and current row) as total from queue) Select person_name from cte Where total
@tenzinchoepheldev7 күн бұрын
My code goes like. -------------------------- with cte as ( select person_name , sum(weight) over ( order by turn) as weight_sum from Queue order by turn desc ) select person_name from cte where weight_sum
@krishnabohidar72262 ай бұрын
select person_name from ( select person_name,weight,turn, sum(weight) over(order by turn) as w from Queue) xyz where xyz.w