LeetCode Medium 1596 Amazon Interview SQL Question with Detailed Explanation

  Рет қаралды 3,691

Everyday Data Science

Everyday Data Science

Күн бұрын

Пікірлер: 16
@florincopaci6821
@florincopaci6821 2 жыл бұрын
it's impossible not to understand how you explain, I haven't seen anyone explain how you explained for example the problem with self join with managers up to level 3. You should be a trainer if you are not already. All the best!
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Thank you Florin for such kind words. I’m glad these videos are helping some people.
@florincopaci6821
@florincopaci6821 2 жыл бұрын
@@EverydayDataScience A lot.Thank you
@yashnikhare2210
@yashnikhare2210 2 жыл бұрын
We can also use Rank Function cte2 as (select *,rank() over(partition by customer_id order by num_ordered desc ) as rnk from cte Then use where clause (where rnk=1)
@mickyman753
@mickyman753 Ай бұрын
yeah just instead of count=first value, rank=1 wala filter aaega last select query mai
@rinkali7654
@rinkali7654 2 жыл бұрын
Very very helpful! Could you please tell when SQL medium questions will have more uploads?
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Hey Rinka, it's coming tomorrow. Happy querying!
@kavyatripathi2151
@kavyatripathi2151 2 жыл бұрын
Please solve Hoppers Company questions on leetcode sql
@harshilgandhi8415
@harshilgandhi8415 2 жыл бұрын
Could we have used max window function in the cte2?
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Great catch, Harshil. Yes, we can use MAX as well. The cte2 code will look something like this: cte2 AS (SELECT *, MAX(num_ordered) OVER(PARTITION BY customer_id) AS most_frequent FROM cte
@adityams1659
@adityams1659 2 жыл бұрын
yess, But if you think about it, the shown method is more efficient. Since you have already used *Order by num_ordered desc* the first value by default is the value we want. if we use Max on it again we are unnecessarily increasing computational complexity
@lakshmivenkatavarun8406
@lakshmivenkatavarun8406 Жыл бұрын
Can anyone explain why we used LEFT JOIN to join cte2 and products?
@nitinmadan4009
@nitinmadan4009 9 ай бұрын
because we want to keep all the customer_id from the cte2.
@mlvprasadofficial
@mlvprasadofficial 2 жыл бұрын
55
@james-r685
@james-r685 Жыл бұрын
another solution: with cte1 as ( select customer_id,product_id,count(1) as ct from orders group by customer_id,product_id ), cte2 as ( select *,dense_rank() over(partition by customer_id order by ct desc) as dr from cte1 ) select a.customer_id,a.product_id,b.product_name from cte2 a left join products b on a.product_id=b.product_id where dr=1
LeetCode Medium 1831 Interview SQL Question with Detailed Explanation
13:14
Everyday Data Science
Рет қаралды 2,7 М.
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
SQL Joins: Difference Between Inner/Left/Right/Outer Joins
10:52
LeetCode 1501: Countries You Can Safely Invest In [SQL]
12:17
Frederik Müller
Рет қаралды 2,3 М.
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН