Introduction
- In this article we will solve Teams Power Users SQL question which is asked by Microsoft as per DataLemur website.
If you don’t know DatLemur then please do visit , it’s one of the best website to practice SQL questions and improve your SQL skills.
Question
- We have been given user_transactions input table. our goal is to find out 3rd transaction made by each user.
Solution
- First we will partition uber_transaction table based on user_id, we will add row_number as column to rank each record.
- Here is output.
- Now once we have our base table is ready , we can return cases where row_number is 3
Final Solution
select user_id,spend,transaction_date from(
select user_id,spend,transaction_date,
row_number() over(partition by user_id order by transaction_date) as rn
from transactions
) x where rn = 3
Submission
- Our solution is accepted by the platform.
Conclusion
- In this article we solved SQL question asked by Uber. we used window operation and used row_number function to rank each record in the partition.
Bonus Tip
- If you want to upskill your SQL interview game, you can definitely check out this bestseller course