Real Data Science SQL Interview Questions and Answers # 2 | Data Science Interview Questions
Key Takeaways
The video covers real data science SQL interview questions and answers, providing a walkthrough of a data science SQL interview in a real interview style, with resources for learning SQL for data science interviews, including a course and a discount for a complete data science training.
Full Transcript
hey everyone welcome back to the channel today we'll be going through another sql mock interview question just like they do it in the fang interviews so you guys seem to have liked it a lot last time where i went through a real interview question and then went through step by step how i approached it how i actually wrote the query and finally how i checked my answers using some dummy data i made up on db sql so today we'll be doing another question just like that all right let's get started today's question is write a sql query to find out the overall friend acceptance rate for each date the table was given to us and that is friend request ds which is date stamp sender receiver and action and action can be sent accepted rejected etc okay cool so just reading the question another time we want the overall friend acceptance rate for each day so our final table should look something like ds so date spam for each day and then the overall so we can call that friend acceptance rate oops and this is essentially going to be accepted divided by total and might as well make that percentage so times 100 okay so let's see i have some assumptions for this table um so my assumption is that the action here is sent accepted rejected i'm going to assume that these actions like if a sender sends it over to the receiver and they didn't respond to it that would actually be counted as sent and then other actions can be accepted and rejected and this is important because when we're doing our total calculation over here that means that the total amount is going to be all the actions combined together okay oh and also um another assumption i'm gonna make is that we're gonna only have unique rows over here so if a sender would then send something to the receiver and you know send it multiple times that wouldn't count okay so let's get started writing our query oops from friend requests so we're grouping by ds and then our next step is accepted over count of options times 100 so we have our select statement we're going to be selecting oops what am i doing group by one select yes yeah so we're grouping by date stamp and then here i'm gonna use a case when statement so case when action is equal to accepted then one else no oops let's just split this up so it's easier to see else know and i'll go over in a bit um about exactly what that means so i want to count that and that should give us the number of people that are accepted i'll also go over why i'm multiplying by 1.00 um and then we're going to divide that by total count option multiply that by a hundred and that should equal the percentage acceptance okay so i'm going to go over this step by step so grouping by one which is the date stamp over here and this is when i'm using a case when statement so here i'm saying that when the case one action is equal to accepted then we're going to count that as the number one else is going to be null and that is our statement and we are counting that so that it's basically counting only the times when the action is equal to accepted and then other times we're not going to count that at all and it's actually really important here for us to write else null not like else zero because the way that sql works when you're counting something it will count just the number um of rows that you have over here but if you have null it wouldn't count it so if you actually put else zero it would count zero as well because it's just simply counting the number of rows and i'm multiplying by 1.00 here and that's because there's something called integer division so when you're dividing an integer by another integer the default is that your number that you get is going to be a whole number so they're just going to round um i think it either rounds up or rounds down i'm not sure but if you basically don't get an actual fraction and we want the fraction of it so i'm multiplying it by a float and that will change it to a float so when we're doing the division over here we'll actually get a fraction instead um so yeah we're going to divide that by the count action which is all the actions that are there which is our total and then we're multiplying that by 100 in order to get a percentage and that is our percentage acceptance that looks right to me yeah that looks that looks pretty good to me um so i don't really see anything else over here uh in terms of optimizing i also don't see too much optimization you know i don't really see any optimization um do let me know in the comments though if you guys have a different approach to this or even if it could be more efficient it could be less efficient i i'll just be really interested in knowing what the way that you guys approach this question as well um there's really lots of ways of doing a query so also don't think that this is you know the way that you have to do it no it's it's definitely not um so yeah i think in terms of this query i am pretty good to go uh i do want to point out though that the assumption that we made earlier that if a sender sends me to a receiver on the same date and they do that multiple times it would actually only count as one row and if we ever wanted um because we made that assumption over here if we ever wanted to only count that as one time we might have to do a distinct statement in order to do that but since we stated upfront that's what our assumption is so we should be okay i just put in some dummy data that i created earlier um and i'll walk through it with you guys as well so we have our table friend request and you have date stamp which is a date sender which is an int receiver which is also in an action which is a var chart and we're going to insert into this friend request table ds sender receiver in action and the values that we had our current day so in postgres current day is a shorthand for today so we have current day sender is one receiver is two and action is sent then i have another one from one to three today that is accepted and then we have current day minus one so that's going to be yesterday and we have one to five rejected another one from yesterday one two three accepted and we're gonna have another one current day minus two from two days ago and that's two to three and that's accepted so i created quite a few rows of dummy data because i'm usually pretty paranoid just in case i like forgot some edge cases where this doesn't work out so i tend to like create more scenarios and see if it works out or not all right let us put in our query cross our fingers that are works please work and success okay cool let's go over this a little bit and just to make sure that it actually works okay so september 9th today is the eleven so that's from two days ago so it's the last line over here and we have accepted so that looks right to me we have 100 acceptance rate and then for september 11th which is today we should have let's see 50 and we do have 50 and finally for the 10th over here rejected accepted we should also have 50 which we do over here as well so this looks pretty good to me yeah seems like we did it oh actually one thing um it's not that big of a deal but you know percent acceptance here there's just like a lot of zeros afterwards if you ever want to round that number up you can do something like round two and this will round it to two decimal places you can also do whatever number that you want so yeah that looks good so i hope you guys enjoyed this video of me going through another sql interview question exactly the way that i did it for my fang interview and this is also the way that i studied for my fang interview where i went through everything step by step and also talk through the entire query i prefer to do it this way um because when you're with an interviewer first of all it's a lot less awkward and second of all if you make a mistake in your logic or when you're writing a query even it's like a small syntax error the interviewer can actually know that you're making that mistake and correct you so you don't you know accidentally go off on the wrong track so i think that's really really helpful since you guys also really enjoyed this style video these sql mock interview question walkthroughs i've also decided to make this into a series so i'll be posting one video a week in this exact style where i'll be going over a sql interview question if you're currently interviewing or even just planning to interview in the future for data science positions i highly recommend that you follow this series and not just watch me do the questions but actually do the questions yourself as well and just follow along and since we're going to be doing this one time every week i think by the time that you're actually going to be interviewing for real you guys are going to do really really well on the interviews and finally shout out to andrew from data leap he's been doing some really cool stuff on his channel and in particularly relevant to this video he's doing sequel interview questions as well and he's doing them live so if you guys are looking for more videos for sql practice head over to his channel and check that out i'll be linking it above as well that's it for this video and thank you so much for sticking to the very end i'll see you in the next video
Original Description
Hi friends! Welcome back to SQL Sundays! A weekly SQL data science interview questions and answers walkthrough.
This is another data science SQL interview question and answer done from beginning to end in a real interview style.
🔗Affiliates
========================
My SQL for data science interviews course (10 full interviews):
https://365datascience.com/learn-sql-for-data-science-interviews/
365 Data Science:
https://365datascience.pxf.io/WD0za3 (link for 57% discount for their complete data science training)
Check out StrataScratch for data science interview prep:
https://stratascratch.com/?via=tina
📲Socials
========================
instagram: https://www.instagram.com/hellotinah/
linkedin: https://www.linkedin.com/in/tinaw-h/
discord: https://discord.gg/5mMAtprshX
🤯Study with Tina
========================
Study with Tina channel:
https://www.youtube.com/channel/UCI8JpGrDmtggrryhml8kFGw
How to make a studying scoreboard:
https://www.youtube.com/watch?v=KAVw910mIrI
Scoreboard website:
scoreboardswithtina.com
livestreaming google calendar:
https://bit.ly/3wvPzHB
🎥Other videos you might be interested in
========================
SQL Sundays Playlist:
https://www.youtube.com/playlist?list=PLVD3APpfd1tuXrXBWAntLx4tNaONro5dA
How I learned SQL from Scratch in 11 Days to Pass my FANNG SQL Interview: https://www.youtube.com/watch?v=vaD3ZFFNwhM
How I consistently study with a full-time job:
https://www.youtube.com/watch?v=INymz5VwLmk
How I would learn to code (if I could start over):
https://www.youtube.com/watch?v=MHPGeQD8TvI&t=84s
🐈⬛🐈⬛About me
========================
Hi, my name is Tina and I'm a data scientist at a FAANG company. I was pre-med studying pharmacology at the University of Toronto until I finally accepted that I would make a terrible doctor. I didn't know what to do with myself so I worked for a year as a research assistant for a bioinformatics lab where I learned how to code and became interested in data science. I then di
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Tina Huang · Tina Huang · 12 of 60
1
2
3
4
5
6
7
8
9
10
11
▶
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
How to choose between software engineering and data science | 5 Key Considerations
Tina Huang
How I got Software Engineering and Data Science Internships | Computer Science Job Search Part 1
Tina Huang
How I Became a Data Scientist | Computer Science Job Search Part 2
Tina Huang
3rd Year Statistics, Data Science, Computer Science Resume | Reviewing Your Resumes Ep. 1
Tina Huang
How to learn SQL for data science interview (the minimize effort maximize outcome way)
Tina Huang
3rd Year CS Resume (and asian drink) Review | Reviewing Your Resumes Ep. 2
Tina Huang
Are you a student? If yes, this is the best data science project for you!
Tina Huang
The Ultimate Guide to Land a Data Science Internship | schedule and time management survival guide
Tina Huang
Upenn MCIT Program Details and Real Student Experiences - Dr. Arvind Bhusnurmath
Tina Huang
Real Data Science SQL Interview Questions and Answers # 1 | Data Science Interview Questions
Tina Huang
3 More Unique and Impactful Projects to get a Data Science Job
Tina Huang
Real Data Science SQL Interview Questions and Answers # 2 | Data Science Interview Questions
Tina Huang
THANK YOU FOR 1000! | Proper intro | Random facts about myself
Tina Huang
A day in the life of a data scientist (FAANG data scientist remote)
Tina Huang
SQL Data Science Interview Questions and Answers (interview style walk-through) | Question 3
Tina Huang
Biology to Data Science (data professor's tips on how to get a data science research position)
Tina Huang
SQL Data Science Interview Questions and Answers (interview style walk-through) | SQL Sundays #4
Tina Huang
Data Science SQL Interview Question Walkthrough | SQL Sundays #5
Tina Huang
Data Science Resume Round-Up With @KenJee_ds - Episode 2
Tina Huang
SQL Data Science Interview Question Walkthrough | SQL Sundays #6
Tina Huang
Data Science vs Software Engineering Interview | 3 Key Differences
Tina Huang
Data Science SQL Interview Question Walkthrough (real interview style) | SQL Sundays #7
Tina Huang
The data science resume that got me my FAANG (MANGA?) job (entry level data scientist)
Tina Huang
Data Science SQL Interview Question Walkthrough (real interview style) | SQL Sundays #8
Tina Huang
Interview with a quant trader
Tina Huang
How I chose my masters degree (as an international student)
Tina Huang
The software engineering resume that got me into FAANG and Goldman Sachs (internship)
Tina Huang
3 tips to avoid debt for a masters #SHORTS
Tina Huang
A hard work day (ft. new NLP project) | FAANG data science isn't chill | vlog 1
Tina Huang
The comments sections are WILD | YouTube sentiment analysis - Data science project for beginners
Tina Huang
Do you have what it takes to be a great data scientist?
Tina Huang
How to learn data science in 2022 (the minimize effort maximize outcome way)
Tina Huang
A productive day as a data scientist | day in the life of a data scientist vlog #2
Tina Huang
How to learn math for data science (the minimize effort maximize outcome way)
Tina Huang
Internship that made me rethink my career...(technology summer analyst at Goldman Sachs)
Tina Huang
How to get a data science job
Tina Huang
cake and big sister advice 🖤
Tina Huang
the most underrated data job in 2021
Tina Huang
My career changing computer science masters degree in 15 minutes (Upenn MCIT)
Tina Huang
Data science interview tips (product and technical interviews)
Tina Huang
Needed to learn javascript in 3 hours - would not recommend
Tina Huang
from management consultant to software engineer | Humans of MCIT
Tina Huang
Overview, Review and Study Tips - Google Data Analytics Professional Certificate
Tina Huang
Overview, Review and Study Tips - Google Data Analytics Professional Certificate (condensed version)
Tina Huang
Watch this video before applying to Georgia Tech OMSCS
Tina Huang
How to self study technical things
Tina Huang
What's the best certificate for data analysts? Google vs IBM Data Analyst Certificate
Tina Huang
FAANG Data scientist reviews: Datacamp, Dataquest, 365 Data Science
Tina Huang
How I would learn to code (if I could start over)
Tina Huang
The quant trader interview guide
Tina Huang
We code a trading bot live! @jacobamaral
Tina Huang
Why you should have a portfolio website
Tina Huang
60k cooking and Q&A (ft. Uncle Roger fried rice)
Tina Huang
How to self study using MOOCS (Udemy, Coursera, and other online courses) | self study online
Tina Huang
Data Science SQL Interview Question Walkthrough | SQL Sundays #9
Tina Huang
Watch me build my portfolio! | How to create a portfolio website
Tina Huang
How I stop myself from burning out
Tina Huang
How I take notes - Tips for efficient note taking that speeds up learning
Tina Huang
How I design effective study plans for ANY SUBJECT (and stick with them) | trading, coding etc.
Tina Huang
How I'm learning to trade (forex swing trading)
Tina Huang
More on: SQL Analytics
View skill →Related Reads
📰
📰
📰
📰
A lightweight workflow for keeping up with AI conference papers
Dev.to · Daniel
Why CitedEvidence Believes Great Researchers Read Less Than You Think
Medium · AI
How to Write a Literature Review That Actually Argues Something
Medium · Machine Learning
I Built a Personal Paper Engine to Stop Losing Research Papers
Dev.to · Ethan
🎓
Tutor Explanation
DeepCamp AI