LeetCode Interview SQL Question with Detailed Explanation | Practice SQL | LeetCode 586

  Рет қаралды 14,599

Everyday Data Science

Everyday Data Science

Күн бұрын

Пікірлер: 24
@deepanshudutta4443
@deepanshudutta4443 2 жыл бұрын
Sir awasome... everyday i solve problems by taking help from your videos
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Keep it up, Deepanshu. Consistency is the key !
@ayushtyagi4240
@ayushtyagi4240 2 жыл бұрын
select customer_number from Orders group by customer_number order by count(customer_number) desc limit 1 this is also one way
@AbhishekSingh-vl1dp
@AbhishekSingh-vl1dp Жыл бұрын
select customer_number from Orders group by customer_number order by count(order_number) desc limit 1 this is much simple
@mahaksingg
@mahaksingg 3 ай бұрын
u r doing a great job thanks
@rayyanamir8560
@rayyanamir8560 2 жыл бұрын
with cte as ( select*,count(order_number) over (partition by customer_number) as count_of_order from orders ) ,cte2 as ( select*, dense_rank() over(order by count_of_order desc) as rank_of_orders from cte ) select customer_number from cte2 where rank_of_orders=1 limit 1
@luyaowang4606
@luyaowang4606 6 ай бұрын
hhh, not sure if this one is faster
@abhisheksharma6617
@abhisheksharma6617 2 ай бұрын
May not be the best approach, but works : select customer_number from orders group by customer_number having count(*) > 1 order by count(*) desc limit 1;
@mlvprasadofficial
@mlvprasadofficial 2 жыл бұрын
8TH ONE COMPLETED..TQ
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Awesome work, keep it up.
@RahulSharma-ht2xz
@RahulSharma-ht2xz Жыл бұрын
thank you so much sir
@pankajchandel1000
@pankajchandel1000 Жыл бұрын
with cte as (select count(order_number) as NumOdr from Orders group by customer_number) select customer_number from cte where NumOdr = (select max(NumOdr) from cte);
@RitzFootball
@RitzFootball 2 жыл бұрын
Learned new concept of CTE, nicely explained, 1 doubt that is why are we mentioning FROM cte again in the end . u have already mentioned FROM cte in the 9th line.can u pls explain this. thank you.
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Okay, so you can't write WHERE NumOrd = MAX(NumOrd). You need to calculate the MAX of that column. So firstly the subquery, SELECT MAX(NumOrd) FROM cte executes and finds the maximum value. Then the cursor goes to outer part i.e. FROM cte it SELECTs customer_number and filters only those rows where NumOrd is equal to Maximum (WHERE NumOrd = the maximum value calculated from the subquery)
@pankajchandel1000
@pankajchandel1000 Жыл бұрын
select customer_number,count(order_number) from Orders group by customer_number having count(order_number)= select max(NumOdr) from(select count(order_number) as NumOdr from Orders group by customer_number )
@pranveshpandey6316
@pranveshpandey6316 11 ай бұрын
Hi, can you please help with this query which i have written, it passes the testcase wnat to know if it is more efficient than yours? select t.customer_number from (select customer_number, count(customer_number) as countcc from Orders group by customer_number order by countcc desc limit 1) as t
@MyAnish22
@MyAnish22 9 ай бұрын
No semi colon required for cte queries?
@s.211
@s.211 Жыл бұрын
select customer_number from orders group by customer_number having count(customer_number) >= all(select count(customer_number) from orders group by customer_number );
@TheEleetcoder
@TheEleetcoder Жыл бұрын
excellent!!
@EverydayDataScience
@EverydayDataScience Жыл бұрын
Glad that you found it useful.
@arunraj3866
@arunraj3866 5 ай бұрын
Select customer _number from Orders groupby customer_number Having Count(customer_number) >1 Will this work?
@hemanthtummala753
@hemanthtummala753 2 жыл бұрын
instead we can use limit 0,1
@dynamickaushik2568
@dynamickaushik2568 6 ай бұрын
The query in this video is correct. 👍 I tried other solution which is as follows SELECT MAX(customer_number) AS customer_number FROM Orders This query is accepted by Test Result. However, when I click the Submit button it shows Wrong answer. Later on I read the whole question again, then I found at the very end there is "Follow Up" information that also must be considered. So, that's why the query in this video is correct.
@anirbansarkar6306
@anirbansarkar6306 2 жыл бұрын
with cte as( select customer_number, count(*) as total_orders from Orders group by customer_number ), cte2 as( select customer_number, dense_rank() over(order by total_orders desc) as ranku from cte ) select customer_number from cte2 where ranku=1
LeetCode 1280 Interview SQL Question with Detailed Explanation | Practice SQL
20:13
Какой я клей? | CLEX #shorts
0:59
CLEX
Рет қаралды 1,9 МЛН
Learn SQL In 60 Minutes
56:24
Web Dev Simplified
Рет қаралды 2,2 МЛН
LeetCode Medium 1596 Amazon Interview SQL Question with Detailed Explanation
16:38
CS50x 2024 - Lecture 7 - SQL
2:14:05
CS50
Рет қаралды 544 М.
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 26 М.
LeetCode 1795 Interview SQL Question with Detailed Explanation | Practice SQL
12:05
Какой я клей? | CLEX #shorts
0:59
CLEX
Рет қаралды 1,9 МЛН