Master SQL Window Functions for Data Science Interviews in 2023

preview_player
Показать описание
In this video, I take an even closer look at window functions by going over three examples using three functions: aggregate functions, ranking functions and analytic functions.

🟢Get all my free data science interview resources

// Comment
Got any questions? Something to add?
Write a comment below to chat.

// Let's connect on LinkedIn:

====================
Contents of this video:
====================
00:00 Review
01:01 Aggregate Functions Example
02:19 Ranking Functions Example
05:53 Analytic Functions Example
09:10 Advantage of Window Functions
Рекомендации по теме
Комментарии
Автор

For 1454 SQL server. this approach needs distinct login_date


select distinct lg.id, a.name
--, lag4, login_date, DATEDIFF(day, lag4, login_date)
from (
select id,
login_date,
LAG(login_date, 4) over(partition by id order by login_date) as lag4
from (select distinct id, login_date from logins) x
) lg
join accounts a
on lg.id=a.id
where DATEDIFF(day, lag4, login_date)=4
order by id

arimaauto
Автор

Very useful. really appreciate your effort in giving the educational session to the public!!!

Heather-bz
Автор

Thanks Emma for coaching. Now I comprehend what window functions are and what kind of problems could be resolved with window functions. Appreciated😀

danielkoo
Автор

You cover everything... This is awesome!!!

Albertelmstreet
Автор

Thanks. Sqlzoo window function section is broken with system errors so this helped a lot. Thank you.

eegernades
Автор

I used lead() for the active users question. I guess instead of looking back, you are looking ahead. If the question asked for a start or end of 5 consecutive day period, then it'll matter right?

Art.of.the.Warriors
Автор

1454 My SQL solution uses lead

select distinct lg.id, a.name
from (
select id,
login_date,
Lead(login_date, 4) over(partition by id order by login_date) as lag4
from (select distinct id, login_date from logins) x
) lg
join accounts a
on lg.id=a.id
where DATEDIFF(lag4, login_date)=4
order by id

arimaauto
Автор

hey Emma, I run your solution for the Active User question on Leetcode, but it returns wrong answer. Can you please check?

isabellaxu