Amazon SQL Interview Question for Data Scientists and Data Analysts (StrataScratch 10322)

  Рет қаралды 34,489

Frederik Müller

Frederik Müller

3 жыл бұрын

Solution and walkthrough of a real SQL interview question for Business Intelligence Engineer, Data Scientist and Data Analyst technical coding interviews. This question was asked by Amazon and is called "Finding User Purchases".
Try this question on StrataScratch: platform.stratascratch.com/co...
Check out another question from Amazon: • Another Amazon SQL Int...
Find me on LinkedIn: / frederikmueller
Playlists:
StrataScratch SQL Coding Questions: • StrataScratch Coding Q...
LeetCode database SQL problems: • LeetCode Database Prob...
LeetCode easy SQL problems: • LeetCode Easy Database...
LeetCode medium SQL problems: • LeetCode Medium Databa...
LeetCode hard SQL problems: • LeetCode Hard Database...

Пікірлер: 21
@frederikmuller
@frederikmuller 2 жыл бұрын
Try this question yourself: platform.stratascratch.com/coding/10322-finding-user-purchases?via=frederik
@praveensinghrathore4542
@praveensinghrathore4542 2 жыл бұрын
The fact that you solved it while recording and didn't practice it before hand, and still be able to deliver such a good explanation, KUDOS to you💛
@SagarKumar-db2xy
@SagarKumar-db2xy 2 жыл бұрын
Underrated channel
@shubham900100
@shubham900100 2 жыл бұрын
select user_id from (select *,lag(created_at) over(partition by user_id order by created_at) as la from amazon_transactions order by user_id) a group by user_id having min(created_at-la)
@satviknaren9681
@satviknaren9681 Жыл бұрын
Very much helpful !
@ceyhunozturk5115
@ceyhunozturk5115 Жыл бұрын
Thanks Frederik
@eb_reviews
@eb_reviews 2 жыл бұрын
Thank you!
@Info-Galaxy
@Info-Galaxy 2 жыл бұрын
Oracle query for same WITH cte AS (SELECT user_id, order_id, order_date, FIRST_VALUE (order_date) OVER (PARTITION BY user_id ORDER BY order_date ASC) AS min_order_date FROM cust_orders) SELECT * FROM cte WHERE cte.order_Date - min_order_Date >= 7
@ajtam05
@ajtam05 2 жыл бұрын
Yeah, I prefer CTEs. It's good to know self joins the way he's doing it (because a lot of existing code will look like that), but easier to understand and compartmentalize with CTE.
@observer698
@observer698 2 жыл бұрын
Why did we need b.created_at >= a.created_at? since we already have the 7 day condition?
@JuliaInMerica
@JuliaInMerica 8 ай бұрын
Or you can use Datediff function
@yuvrajmahendru2149
@yuvrajmahendru2149 2 жыл бұрын
Is strata scratch better than leetcode for SQL and python questions?
@frederikmuller
@frederikmuller 2 жыл бұрын
If you’re preparing for Data Science interviews then StrataScratch, yes. Way more data questions. On Leetcode you can only do algorithmic questions with pythons, not data questions.
@yuvrajmahendru2149
@yuvrajmahendru2149 2 жыл бұрын
@@frederikmuller but the python questions in strata scratch are only using pandas right? No general questions that are asked in interviews to test python knowledge?
@MO3az-hw9qy
@MO3az-hw9qy Ай бұрын
WITH purchase AS ( SELECT user_id, created_at - LAG(created_at) OVER(PARTITION BY user_id ORDER BY created_at) AS difference FROM amazon_transactions ), result As (SELECT CASE WHEN difference >= 0 AND difference
@TuanTran-hk8kj
@TuanTran-hk8kj 2 жыл бұрын
select user_id from (select user_id, min(datediff(created_at, pre_date)) as mindiff from (select user_id, created_at, lag(created_at, 1) over (partition by user_id order by created_at ) as pre_date from amazon_transactions) as df group by user_id) as df2 where mindiff < 8 I find this also produce the same result
@oscararmandocisnerosruvalc8503
@oscararmandocisnerosruvalc8503 Жыл бұрын
WITH cte AS( select user_id,DATE_PART('day',created_at::date)-DATE_PART('day',Date_after::date) as days_between,created_at,Date_after from ( select user_id, created_at, LAG(created_at,1) OVER ( partition by user_id ORDER BY created_at) AS Date_after from amazon_transactions ) as x ) SELECT DISTINCT(user_id) FROM cte where days_between
@malikabaymuradova2344
@malikabaymuradova2344 2 жыл бұрын
why does this give an incorrect answer? there are three numbers included in my output that should not be in the answer with ranked_transactions as ( select *, row_number() over (partition by user_id order by created_at) as rnk from amazon_transactions ), first_transactions as ( select * from ranked_transactions where rnk = 1) select distinct t1.user_id from first_transactions t1 join amazon_transactions t2 on t1.user_id = t2.user_id where t1.id t2.id and t2.created_at::date-t1.created_at::date BETWEEN 0 AND 7
@wowwithdeeksha3947
@wowwithdeeksha3947 Жыл бұрын
please let me know if the below query is correct? SELECT cust_id FROM amazon_transactions WHERE DATEDIFF( Date, LAG(Date) )> 7 GROUP BY cust_id Date PARTITION BY cust_id
@Hamedali92
@Hamedali92 Жыл бұрын
I've used the Lead function and it works: CREATE TABLE #AmazonTransactions( [ID] [int] NULL, [UserID] [int] NULL, [Item] [varchar](50) NULL, [Created_at] [Date] NULL, [Revenue] [int] NULL ) INSERT INTO #AmazonTransactions VALUES(1,101,'Milk','7/1/2022',100) INSERT INTO #AmazonTransactions VALUES(2,101,'Milk','7/5/2022',100) INSERT INTO #AmazonTransactions VALUES(2,101,'Milk','7/15/2022',100) INSERT INTO #AmazonTransactions VALUES(3,102,'Chocolate','7/10/2022',50) INSERT INTO #AmazonTransactions VALUES(4,103,'Biscuit','7/16/2022',20) INSERT INTO #AmazonTransactions VALUES(4,103,'Biscuit','7/20/2022',20) select x.UserID from ( select UserID --,Created_at --,LEAD(Created_at) over (partition by UserID order by Created_at) ,DATEDIFF(DD,Created_at,LEAD(Created_at) over (partition by UserID order by Created_at) ) AS [No. of Days] from #AmazonTransactions A ) x WHERE x.[No. of Days]
What does a Data Analyst actually do? (in 2024) Q&A
14:27
Tim Joo
Рет қаралды 19 М.
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 12 МЛН
Stupid Barry Find Mellstroy in Escape From Prison Challenge
00:29
Garri Creative
Рет қаралды 21 МЛН
Interview with an Amazon BI Engineer
23:36
DataInterview
Рет қаралды 11 М.
Top 5 Data Analyst Interview Mistakes
5:28
Alex The Analyst
Рет қаралды 79 М.
*HARD* IBM SQL Interview Question (StrataScratch 10538)
12:34
Frederik Müller
Рет қаралды 157