Тёмный

PWC Interview Question for Data Analyst Role | SQL Intermediate Question 14 

Code-Con
Подписаться 1,4 тыс.
Просмотров 587
50% 1

Опубликовано:

 

29 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 3   
@arupchandra8602
@arupchandra8602 5 месяцев назад
with cte as( select candidate_id,datepart(year,vote_date)*100+''+datepart(month,vote_date) as weeks ,count(voter_id) counts from elections group by datepart(year,vote_date)*100+''+datepart(month,vote_date),candidate_id ),cte2 as( select * ,RANK() OVER(PARTITION BY weeks order by counts desc)rn from cte) select * from cte2 where rn=1;
@zaravind4293
@zaravind4293 8 месяцев назад
HI bro, We can use dense rank in the first select statement itself so that we can reduce one cte. Please find my solution below select month,cid,votes from ( select extract(month from vdate) month, cid, count(vid) votes, dense_Rank() over(partition by extract(month from vdate) order by count(vid) desc) rk from pwc group by extract(month from vdate),cid order by 1 ) where rk=1;
@Code-Con
@Code-Con 7 месяцев назад
Yeah all right with this one 👍🏾