LeetCode Medium 1308 Interview SQL Question with Detailed Explanation | Practice SQL

preview_player
Показать описание

In this video I solve and explain a medium difficulty leetcode SQL question using MySQL query. This question has been asked in Apple, Facebook, Amazon, Google, Adobe, Microsoft, Adobe interviews or what we popularly call FAANG interviews.
I explain the related concept as well. This question includes points to keep in mind to develop SQL queries.

LeetCode is the best platform to help you enhance your skills, expand your knowledge and prepare for technical interviews.

If you found this helpful, Like and Subscribe to the channel for more content.

#LeetCodeSQL #FAANG #SQLinterviewQuestions
Рекомендации по теме
Комментарии
Автор

difference between ROWS and RANGE :
ROWS specifies the number of rows that precede or follow the current row and
RANGE specifies the range of values wrt the current row

saisushanthdurvasulabitsian
Автор

Sir, Thanks a lot for This Amazing Video 😊
Problem - 49 Solved ✅ in Practice SQL - LeetCode 👩🏻‍💻

PrithaMajumder
Автор

If we just use ORDER BY a.day, a. gender inside the OVER clause... We will get the cumulative sum in each row.

Tried this and it worked without using 'ROWS BETWEEN....'

Tested this with MAX() window function... By default, OVER clause selects only preceding rows when ORDER BY is used in it.

sohailshaikh
Автор

SELECT
gender,
day,
SUM(score_points) OVER (
PARTITION BY gender order by gender, day
) AS total
FROM Scores; this query works correctly sir

KathirVel-nbkf
Автор

because combination of primary, day is a primary key, so we don't need to add distinct gender

fazilhussain
Автор

select
gender, day,
sum(score_points) over(partition by gender order by day) as total,
sum(score_points) over(PARTITION BY gender ) as total_overall
from scores
order by gender

Output:
gender, day, total, total_overall
F, 2019-12-30, 17, 80
F, 2019-12-31, 40, 80
F, 2020-01-01, 57, 80
F, 2020-01-07, 80, 80
M, 2019-12-18, 2, 36
M, 2019-12-25, 13, 36
M, 2019-12-30, 26, 36
M, 2019-12-31, 29, 36
M, 2020-01-07, 36, 36
###
if u don't give order by it will give u cumulative sum for that window else it will give overall sum for the specified window(partition by)

chargeurself
Автор

select *, sum(score_points) over(partition by gender order by day) as totalPoint from competition_scores;

divyanshusinghchauhan
Автор

with cte as
(select *, sum(score_points) over(partition by gender order by day)
as prev_col from Scores group by gender, day
order by gender, day)
select gender, day, prev_col as total from cte;

-Joshna
Автор

select gender, day, sum(total) over (partition by gender order by gender, day) as total
from scores
This would also work! Thanks for great videos sir

ushasr
join shbcf.ru