Solving an Amazon SQL Interview Question on Notepad

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

Ankit Bansal

Ankit Bansal

Күн бұрын

Пікірлер: 54
@ankitbansal6
@ankitbansal6 Ай бұрын
Hit the like button and let me know any other questions you want me to solve on notepad . Send it to sql.namaste@gmail.com
@483_saurabhjindal6
@483_saurabhjindal6 Ай бұрын
Sir I have written query for this question. Please check my query in comments
@PowerBiWithVivek
@PowerBiWithVivek Ай бұрын
Can't we us >='2021--01-01' at the end of query, will this not give more accurate result?
@deepeshmatkati3058
@deepeshmatkati3058 Ай бұрын
Your are at point on focusing the problem faced by candidates during an interview, also you are a master of breaking down the problem into chunks and giving us a simpler yet effective solutions!
@nagendras9696
@nagendras9696 Ай бұрын
Amazing video Sir. Please upload more videos in this format only, writing query first in notepad and then executing in SQL server. This will be really helpful in interview preparation
@myjourney352
@myjourney352 Ай бұрын
Thank you so much Ankit, Dateadd function is not with Postgres. I've solved this using this approach. with cte as ( select *, event_date + INTERVAL '1 month' * subscription_period AS Validity_Date, row_number() over(partition by customer_id order by event_date desc) as rn from subscription_history where extract(year from event_date) = 2020 and customer_id not in (select customer_id from subscription_history where event= 'C' and extract(year from event_date) = 2020)) select customer_id,marketplace,event,event_date,Validity_Date from cte where rn=1 and Validity_Date >='2020-12-31'
@rajat1999gupta
@rajat1999gupta Ай бұрын
Thank you for your amazing content on sql, you really are a great sql mentor
@AmanRaj-p8w
@AmanRaj-p8w 16 күн бұрын
Mysql Solution: with cte as ( select *, row_number() over (partition by customer_id, yr order by event_date desc) as rw from ( select *, year(event_date) as yr, month(event_date) as mth from subscription_history ) as x where yr = '2020' ) select customer_id, marketplace, event_date, event, subscription_period from cte where customer_id not in (select customer_id from cte where event = 'c' ) and subscription_period + mth > 12
@AyushAgrawal-l8q
@AyushAgrawal-l8q Күн бұрын
I faced the same problem but with an additional event status ‘E’ which stands for expiration
@mridulraj4334
@mridulraj4334 20 күн бұрын
with cte as ( select customer_id,marketplace,event_date,event,subscription_period, (CASE WHEN event_date = (max(event_date) over (partition by customer_id)) AND event !='C' THEN 1 ELSE 0 END) as flag, DATEADD(month,subscription_period,event_date) as subscription_end_date from subscription_history where event_date='2020-12-31' GROUP BY marketplace
@AyushAgrawal-l8q
@AyushAgrawal-l8q Күн бұрын
I faced the same problem but with an additional event status ‘E’ which stands for expiration. Can you help the community by adding this additional event and solving for that as well ?
@chitturusaianisha4115
@chitturusaianisha4115 14 күн бұрын
Thanks for the video, I have a question, what if the customer cancels on the (max date of year 2020) but still has subscription months left? in the solution we are only checking the customer's (max date of 2020) and event is not in 'C'
@sravankumar1767
@sravankumar1767 Ай бұрын
Superb explanation Ankit 👌 👏 👍
@manaliverma3779
@manaliverma3779 23 күн бұрын
with cte as ( select customer_id, marketplace, event, event_date as event_start_date, dateadd(month, subscription_period, event_date) as event_end_date from subscription_history) select marketplace, count(distinct customer_id) as active_users from cte where event in ('S', 'R') and event_start_date between '2020-01-01' and '2020-12-31' and event_end_date between '2020-01-01' and '2020-12-31' ;
@nikhilpurwar697
@nikhilpurwar697 Ай бұрын
without union with cte as( select customer_id, dateadd(month,subscription_period,event_date) as newdate from subscription_history where event in('R','S')and year(dateadd(month,subscription_period,event_date)) ='2021') select distinct customer_id from cte where customer_id not in (select customer_id from subscription_history where event='C' and year(event_date)='2020')
@bindusharma8625
@bindusharma8625 Ай бұрын
Respected sir, can we solve this question by: select*from subscription_history where event_date
@Sudarshan-d7s
@Sudarshan-d7s Ай бұрын
Bro pls bring more problems like that or just bring a series and KZbin community members pls paste all your interview experiences here so that will help all of us ❤
@ankitbansal6
@ankitbansal6 Ай бұрын
Complex SQL Questions for Interview Preparation: kzbin.info/aero/PLBTZqjSKn0IeKBQDjLmzisazhqQy4iGkb
@avi417
@avi417 2 күн бұрын
with cte as ( select *, row_number () over(partition by customer_id order by event_date desc ) as rn from subscription_history where event_date = '2020-12-31';
@Datapassenger_prashant
@Datapassenger_prashant Ай бұрын
As usual amazing content
@VanshGudka
@VanshGudka Ай бұрын
Sir make some videos on sql projects as well ..
@deaspirant
@deaspirant Ай бұрын
Hi Ankit, I have Experience on Tableau and learning sql and python from your courses is it good to change my career from tableau developer to data engineer, is it easy to work as a data engineer if we don't have real time experience
@vaibhavjain9094
@vaibhavjain9094 Ай бұрын
hello sir is there any difference between your youtube videos and namstesql course ? sir my humble suggestion please make a clear video in which tell us about the course and the difference (if any) between videos you make on youtube. because there is lot of confusion to buy namaste sql or not. if you read this comment at least please reply . thanku
@ankitbansal6
@ankitbansal6 Ай бұрын
On KZbin I have solved multiple problems. The course covers all the concepts from basic to advanced. Along with that you have assignments and projects.
@srinivasulum414
@srinivasulum414 Ай бұрын
Nice Explanation Ankit 👌
@ankitbansal6
@ankitbansal6 Ай бұрын
Thanks 🙂
@mukeshkumaryadav350
@mukeshkumaryadav350 Ай бұрын
Best part is you share the table creation script 😅
@vinil9212
@vinil9212 Ай бұрын
If you want count by location: with cte as ( select *, ROW_NUMBER() OVER (Partition by customer_id order by event_date desc) as rnk from subscription_history where event_date='2020-12-31' group by marketplace;
@483_saurabhjindal6
@483_saurabhjindal6 Ай бұрын
select distinct(customer_id),marketp lace from subscription_history where year(event_date)=2020 and customer_id not in (select distinct customer_id from subscription_history where year(event_date)=2020 and event='C)' group by marketplace
@nikhilpurwar697
@nikhilpurwar697 Ай бұрын
with cte as( select customer_id, dateadd(month,subscription_period,event_date) as newdate from subscription_history where event='R' and year(dateadd(month,subscription_period,event_date)) ='2021' union select customer_id, dateadd(month,subscription_period,event_date) as newdate from subscription_history where event='S' and year(dateadd(month,subscription_period,event_date)) ='2021') select distinct customer_id from cte where customer_id not in (select customer_id from subscription_history where event='C' and year(event_date)='2020')
@prateek-i5w
@prateek-i5w Ай бұрын
Do you have any plans on launching another live session of SQL course?
@ankitbansal6
@ankitbansal6 Ай бұрын
It will take time . Go for recorded once. Later you can join live by paying the difference.
@kedarwalavalkar6861
@kedarwalavalkar6861 Ай бұрын
with cte as ( select * from subscription_history where event_date < '2021-01-01' ) ,cte2 as ( select * from ( select * ,row_number() over(partition by customer_id order by event_date desc) as rn from cte ) x where x.rn = 1 ) select customer_id ,marketplace ,event_date ,subscription_period ,event ,event_date + INTERVAL '1 month' * subscription_period AS valid_until from cte2 where event 'C' And event_date + INTERVAL '1 month' * subscription_period >= '2020-12-31'
@florincopaci6821
@florincopaci6821 Ай бұрын
Hello This is my solution in sql server but is too lenghty and to complicated comparing with your solution- with flo as ( select * , sum(case when year(event_date)=2020 and subscription_period is null then 0 else 1 end)over(partition by customer_id ) as grp, count(event_date)over(partition by customer_id )as cnt, max(case when year(event_date) 2021 and subscription_period is not null then event_date end )over(partition by customer_id)as last_date_not_null from subscription_history ) select customer_id from flo where grp=cnt and subscription_period is not null and event_date=last_date_not_null and dateadd(month, subscription_period, last_date_not_null)>'2020-12-31';
@arjundev4908
@arjundev4908 Ай бұрын
WITH CTE AS(SELECT * FROM subscription_history WHERE event_date = '2020-12-31';
@AkhilManhas-vi1qc
@AkhilManhas-vi1qc Ай бұрын
We already filter date in cte . Then why we use date add
@AkhilManhas-vi1qc
@AkhilManhas-vi1qc Ай бұрын
Samaj gaya
@piyushsingh6084
@piyushsingh6084 Ай бұрын
Hello Ankit, I have purchased the SQL course, but unfortunately the website is not working , Please do the needful I hope it gets resolved asap
@ankitbansal6
@ankitbansal6 Ай бұрын
Checking
@ankitbansal6
@ankitbansal6 Ай бұрын
It's back
@piyushsingh6084
@piyushsingh6084 Ай бұрын
@@ankitbansal6 thanks sir, also the telegram link provided in the Hindi version of SQL ,recorded lectures is not clickable, idk if it's active or not , please check that also if it's active, if it's not what alternative solution I hv to raise doubts if any :)
@rajkumarpanigrahi2013
@rajkumarpanigrahi2013 Ай бұрын
Brother please try to upload video regular
@ankitbansal6
@ankitbansal6 Ай бұрын
Sure
@coding6763
@coding6763 Ай бұрын
new course when ?
@SANDEEPSHARMA-xr1ke
@SANDEEPSHARMA-xr1ke Ай бұрын
Sir need help for this problem
@sagarsonawane9007
@sagarsonawane9007 Ай бұрын
Save Hindus in Bangladesh
@ankitbansal6
@ankitbansal6 Ай бұрын
We are with you. Let us know how we can help.
@bharathms5560
@bharathms5560 Ай бұрын
Okay bro we understand your point but why are you commenting here? It's not the place for that 😥
@Mju98
@Mju98 Ай бұрын
Have some ethics @sagarsonawane9007. I can pray for u if u are bangladeshi hindu. But this is not the right platform. Twitter is there you can contact the officials
@rafidrabbi
@rafidrabbi Ай бұрын
Bangladesh hindus are saved....Dont worry
@rafidrabbi
@rafidrabbi Ай бұрын
Bangladesh hindus are saved....Dont worry
Zepto Product Analyst SQL Interview Question
13:59
Ankit Bansal
Рет қаралды 11 М.
SCHOOLBOY. Мама флексит 🫣👩🏻
00:41
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 7 МЛН
Bike Vs Tricycle Fast Challenge
00:43
Russo
Рет қаралды 63 МЛН
Шок. Никокадо Авокадо похудел на 110 кг
00:44
20 Years of SQL Advice in 11 Minutes
11:01
Database Star
Рет қаралды 7 М.
Forward Fill Null Values  - 2 WAYS TO SOLVE |  Tricky SQL Questions
11:23
Amazon Product Manager Mock Interview: Solving Pain Points
23:10
you need to learn SQL RIGHT NOW!! (SQL Tutorial for Beginners)
24:25
NetworkChuck
Рет қаралды 1,5 МЛН
The 25 SQL Questions You MUST Know for Data Analyst Interviews
32:47
KSR Datavizon
Рет қаралды 223 М.