Real Data Science SQL Interview Questions and Answers # 1 | Data Science Interview Questions

Tina Huang · Advanced ·📄 Research Papers Explained ·5y ago

Key Takeaways

This video covers real data science SQL interview questions and answers, providing a walkthrough of a mock interview, and offers resources for learning SQL for data science interviews, including a course and practice platforms like StrataScratch.

Full Transcript

hey everyone welcome back to another video so some of you have reached out to me in the past couple weeks or so asking me to make more sql videos specifically uh walkthroughs of sql interview questions so your wish is my command and here it is by the way if you watch my past video about how i learned sql from scratch in 11 days to pass my fang data science interview you would know that i have an obsession with my whiteboard i prefer to do everything on my whiteboard however you guys did make a really good point because interviews are going to be virtual now so they're probably going to also um that final whiteboarding round is going to be virtual as well and they're going to use something called coderpad usually which is just like a text editor similar to sublime text so i'm gonna just show you guys using sublime because i think coderpad is paid and it's pretty much the same thing anyway all right so let's get started the question that we're gonna be looking at today is a sql interview question asked by a tech company the question is write a sql query to count the number of unique users per day who logged in from both iphone and web where iphone logs and web logs are in distinct relations so this question doesn't tell us um what the iphone logs and web logs actually looks like so we're going to have to make some assumptions here all right so let's see for iphone logs let's call that iphone um i'm gonna assume that it's gonna be time stamps called ts user id and iphone session id and similarly for web blog it's going to be timestamp user id and web session id okay so i'm going to just assume that this is what our relations are going to be looking like and now i'm going to write down each step of how to tackle this query so the first step is going to be join so we want to join together the iphone and the web tables uh and then after that we're gonna be matching by day and user id and finally we're going to be grouping by the day and we want to count the number of users per day so our final table is probably going to look something like uh day num users all right so we now know what it is that we want it to look like all right so time to write the query from iphone i join web and we're going to be joining on here match by day and user id so ida user id is equal to w dot user id and so we're going to be joining by the day but time stamp our assumption is that um it actually includes both the day and that time associated with that but since we only care about the date and we don't actually care about the granularity of the hours where the minutes or the seconds so we can actually truncate that so the function here is date trunk uh day and i dot user oops not user id i dot ts is equal to date trunk day w dot ts so that should match by day all right so our third step here is to group by the day and count the number of users okay so let's write the select statement first we want the day over here so we're gonna do date trunk again day i dot yes as day and then we're going to count the number of users so count so the number of users we want are unique so we want to count distinct oops uh i dot user id as num users and um i just wanted to make a point here in saying that we used an inner join because we didn't specify what kind of join that we're using so that should only join together users that were logged in from both iphone and web all right so we need to write the group by clause so group by one all right let us look this over one more time select date trunk okay so that should give us the day and it should give us the count as the number of users iphone i web here joining is correct okay so that looks correct to me and now i'm going to think about if there's any ways of making it more optimized okay so i think that this is pretty much as optimal that you can get um like we need to distinct here in case like people log in on their iphone and web multiple times throughout the day we only can't want to count the number of users that are there so we do need that and in terms of date trunk i mean there could be a function that's more efficient than that but i think this is fine okay yeah this looks good to me so our final step now is to actually test out this query and see if we made any mistakes before we get into that i just wanted to say that if you're enjoying this video and finding it useful consider liking the video and even subscribing to the channel um i'm planning to make more videos like these depending on you know how much you guys like them um but yeah like that's your interactions with me and your engagements is how i engage how useful you guys are finding my material and it really motivates me to make more videos like these all right so this is sql fiddle and i just copy pasted some dummy data that i made previously uh just like for the sake of time you guys don't have to watch me trying to come up with data to play in um but i'll still go over it with you guys though so i created two tables one called webco one called iphone which is exactly the tables that we assume that we were having when you're writing the query so it has timestamp user id web session id and for iphone has timestamp user id and iphone session id and i also just inserted some values in to test that out query with so here we have in web um now so like timestamp is going to be currently user id is 1 and session id is 100 and then this is a from one hour ago it's still the same user and the session is 101 and then i did another one that was from one day ago user id is two to a separate person and the session id is 103. for iphone i did something similar so our same user here user number one and then from two hours ago user number one again i did user one and i did duplicates of this just to make sure that we actually have unique number of users um sorry just to make sure that we have unique users because we don't want duplicates to show up um and then we have from one day ago but this one is different the user id is three so after we run our query the return should be we only have one row for today and we should have number of users is going to be one because the only one that should match is user id number one and only one of them alright so let us copy paste our actual query oops that is not our query this is our query so this is the query that we just wrote um hopefully it works fingers crossed no so many errors oh okay so this is my sql server so i actually wrote this in postgres sql so let's change that and try again yay it worked success all right so this is what we expected um we have today which is september 2nd and number of users is one so depending on how paranoid i am and just kind of like how confident i am in my query sometimes i would add in more dummy data to see if i can like catch any edge cases that my query doesn't wouldn't be able to process but in this case i'm pretty confident that this query will work in all edge cases so yeah i think i'm just going to leave it as that so that was the final step and i just wanted to stress that it's really important to actually test out your queries because oftentimes you know you think that's crap but maybe there's like small syntax error which is i things that you didn't catch previously and this feedback is really important for you actually learning so next time when something like that comes up again you wouldn't make the same mistake twice and that's it for this question this is what i did for all the sql questions i practiced when i was prepping for my own interview at the fane company and um yeah let me know what you guys think about this video i've never done like live coding like this before um so you know let me know if it's like too slow too fast and being like really confusing you know maybe i'm like repeating myself repeatedly something like that right um and if you guys enjoy this video also let me know if you want me to do more like this um maybe it's helpful to see me just like go through more interview questions maybe not just let me know because i know what kind of videos to make in the future as well all right so thank you for watching this video and i'll see you guys next time

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 · 10 of 60

1 How to choose between software engineering and data science | 5 Key Considerations
How to choose between software engineering and data science | 5 Key Considerations
Tina Huang
2 How I got Software Engineering and Data Science Internships | Computer Science Job Search Part 1
How I got Software Engineering and Data Science Internships | Computer Science Job Search Part 1
Tina Huang
3 How I Became a Data Scientist | Computer Science Job Search Part 2
How I Became a Data Scientist | Computer Science Job Search Part 2
Tina Huang
4 3rd Year Statistics,  Data Science, Computer Science Resume | Reviewing Your Resumes Ep. 1
3rd Year Statistics, Data Science, Computer Science Resume | Reviewing Your Resumes Ep. 1
Tina Huang
5 How to learn SQL for data science interview (the minimize effort maximize outcome way)
How to learn SQL for data science interview (the minimize effort maximize outcome way)
Tina Huang
6 3rd Year CS Resume (and asian drink) Review | Reviewing Your Resumes Ep. 2
3rd Year CS Resume (and asian drink) Review | Reviewing Your Resumes Ep. 2
Tina Huang
7 Are you a student? If yes, this is the best data science project for you!
Are you a student? If yes, this is the best data science project for you!
Tina Huang
8 The Ultimate Guide to Land a Data Science Internship | schedule and time management survival guide
The Ultimate Guide to Land a Data Science Internship | schedule and time management survival guide
Tina Huang
9 Upenn MCIT Program Details and Real Student Experiences - Dr. Arvind Bhusnurmath
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
Real Data Science SQL Interview Questions and Answers # 1 | Data Science Interview Questions
Tina Huang
11 3 More Unique and Impactful Projects to get a Data Science Job
3 More Unique and Impactful Projects to get a Data Science Job
Tina Huang
12 Real Data Science SQL Interview Questions and Answers # 2 | Data Science Interview Questions
Real Data Science SQL Interview Questions and Answers # 2 | Data Science Interview Questions
Tina Huang
13 THANK YOU FOR 1000! | Proper intro | Random facts about myself
THANK YOU FOR 1000! | Proper intro | Random facts about myself
Tina Huang
14 A day in the life of a data scientist (FAANG data scientist remote)
A day in the life of a data scientist (FAANG data scientist remote)
Tina Huang
15 SQL Data Science Interview Questions and Answers (interview style walk-through) | Question 3
SQL Data Science Interview Questions and Answers (interview style walk-through) | Question 3
Tina Huang
16 Biology to Data Science (data professor's tips on how to get a data science research position)
Biology to Data Science (data professor's tips on how to get a data science research position)
Tina Huang
17 SQL Data Science Interview Questions and Answers (interview style walk-through) | SQL Sundays #4
SQL Data Science Interview Questions and Answers (interview style walk-through) | SQL Sundays #4
Tina Huang
18 Data Science SQL Interview Question Walkthrough | SQL Sundays #5
Data Science SQL Interview Question Walkthrough | SQL Sundays #5
Tina Huang
19 Data Science Resume Round-Up With @KenJee_ds  - Episode 2
Data Science Resume Round-Up With @KenJee_ds - Episode 2
Tina Huang
20 SQL Data Science Interview Question Walkthrough | SQL Sundays #6
SQL Data Science Interview Question Walkthrough | SQL Sundays #6
Tina Huang
21 Data Science vs Software Engineering Interview | 3 Key Differences
Data Science vs Software Engineering Interview | 3 Key Differences
Tina Huang
22 Data Science SQL Interview Question Walkthrough (real interview style) | SQL Sundays #7
Data Science SQL Interview Question Walkthrough (real interview style) | SQL Sundays #7
Tina Huang
23 The data science resume that got me my FAANG (MANGA?) job (entry level data scientist)
The data science resume that got me my FAANG (MANGA?) job (entry level data scientist)
Tina Huang
24 Data Science SQL Interview Question Walkthrough (real interview style) | SQL Sundays #8
Data Science SQL Interview Question Walkthrough (real interview style) | SQL Sundays #8
Tina Huang
25 Interview with a quant trader
Interview with a quant trader
Tina Huang
26 How I chose my masters degree (as an international student)
How I chose my masters degree (as an international student)
Tina Huang
27 The software engineering resume that got me into FAANG and Goldman Sachs (internship)
The software engineering resume that got me into FAANG and Goldman Sachs (internship)
Tina Huang
28 3 tips to avoid debt for a masters #SHORTS
3 tips to avoid debt for a masters #SHORTS
Tina Huang
29 A hard work day (ft. new NLP project) | FAANG data science isn't chill | vlog 1
A hard work day (ft. new NLP project) | FAANG data science isn't chill | vlog 1
Tina Huang
30 The comments sections are WILD | YouTube sentiment analysis - Data science project for beginners
The comments sections are WILD | YouTube sentiment analysis - Data science project for beginners
Tina Huang
31 Do you have what it takes to be a great data scientist?
Do you have what it takes to be a great data scientist?
Tina Huang
32 How to learn data science in 2022 (the minimize effort maximize outcome way)
How to learn data science in 2022 (the minimize effort maximize outcome way)
Tina Huang
33 A productive day as a data scientist | day in the life of a data scientist vlog #2
A productive day as a data scientist | day in the life of a data scientist vlog #2
Tina Huang
34 How to learn math for data science (the minimize effort maximize outcome way)
How to learn math for data science (the minimize effort maximize outcome way)
Tina Huang
35 Internship that made me rethink my career...(technology summer analyst at Goldman Sachs)
Internship that made me rethink my career...(technology summer analyst at Goldman Sachs)
Tina Huang
36 How to get a data science job
How to get a data science job
Tina Huang
37 cake and big sister advice 🖤
cake and big sister advice 🖤
Tina Huang
38 the most underrated data job in 2021
the most underrated data job in 2021
Tina Huang
39 My career changing computer science masters degree in 15 minutes (Upenn MCIT)
My career changing computer science masters degree in 15 minutes (Upenn MCIT)
Tina Huang
40 Data science interview tips (product and technical interviews)
Data science interview tips (product and technical interviews)
Tina Huang
41 Needed to learn javascript in 3 hours - would not recommend
Needed to learn javascript in 3 hours - would not recommend
Tina Huang
42 from management consultant to software engineer | Humans of MCIT
from management consultant to software engineer | Humans of MCIT
Tina Huang
43 Overview, Review and Study Tips - Google Data Analytics Professional Certificate
Overview, Review and Study Tips - Google Data Analytics Professional Certificate
Tina Huang
44 Overview, Review and Study Tips - Google Data Analytics Professional Certificate (condensed version)
Overview, Review and Study Tips - Google Data Analytics Professional Certificate (condensed version)
Tina Huang
45 Watch this video before applying to Georgia Tech OMSCS
Watch this video before applying to Georgia Tech OMSCS
Tina Huang
46 How to self study technical things
How to self study technical things
Tina Huang
47 What's the best certificate for data analysts? Google vs IBM Data Analyst Certificate
What's the best certificate for data analysts? Google vs IBM Data Analyst Certificate
Tina Huang
48 FAANG Data scientist reviews: Datacamp, Dataquest, 365 Data Science
FAANG Data scientist reviews: Datacamp, Dataquest, 365 Data Science
Tina Huang
49 How I would learn to code (if I could start over)
How I would learn to code (if I could start over)
Tina Huang
50 The quant trader interview guide
The quant trader interview guide
Tina Huang
51 We code a trading bot live! @jacobamaral
We code a trading bot live! @jacobamaral
Tina Huang
52 Why you should have a portfolio website
Why you should have a portfolio website
Tina Huang
53 60k cooking and Q&A (ft. Uncle Roger fried rice)
60k cooking and Q&A (ft. Uncle Roger fried rice)
Tina Huang
54 How to self study using MOOCS (Udemy, Coursera, and other online courses) | self study online
How to self study using MOOCS (Udemy, Coursera, and other online courses) | self study online
Tina Huang
55 Data Science SQL Interview Question Walkthrough | SQL Sundays #9
Data Science SQL Interview Question Walkthrough | SQL Sundays #9
Tina Huang
56 Watch me build my portfolio! | How to create a portfolio website
Watch me build my portfolio! | How to create a portfolio website
Tina Huang
57 How I stop myself from burning out
How I stop myself from burning out
Tina Huang
58 How I take notes - Tips for efficient note taking that speeds up learning
How I take notes - Tips for efficient note taking that speeds up learning
Tina Huang
59 How I design effective study plans for ANY SUBJECT (and stick with them) | trading, coding etc.
How I design effective study plans for ANY SUBJECT (and stick with them) | trading, coding etc.
Tina Huang
60 How I'm learning to trade (forex swing trading)
How I'm learning to trade (forex swing trading)
Tina Huang

This video provides a realistic walkthrough of a data science SQL interview, covering key concepts and questions, and offers resources for further learning and practice. Viewers can learn how to approach SQL interview questions and improve their data science skills. The video is part of a series, SQL Sundays, and is presented by Tina Huang, a data scientist at a FAANG company.

Key Takeaways
  1. Prepare for a data science SQL interview by practicing with real-world questions
  2. Learn how to write efficient SQL queries for data analysis
  3. Optimize SQL queries for better performance
  4. Apply SQL to solve real-world data science problems
  5. Use resources like StrataScratch and 365 Data Science to improve skills
💡 Practicing with real-world SQL interview questions and using the right resources can significantly improve one's chances of success in a data science interview.

Related AI Lessons

I Spent Weeks Looking for a Research Gap Before I Realized I Was Searching the Wrong Way
Learn how to effectively find research gaps by changing your approach, a crucial skill for AI researchers and academics
Medium · AI
ICMI 2026 Reviews [D]
Learn how to interpret ICMI 2026 reviews and improve your paper's acceptance chances
Reddit r/MachineLearning
Workshop submission for main conference paper under review [D]
Learn how to navigate submitting a paper to a non-archival workshop before the final decision of a main conference like ECCV
Reddit r/MachineLearning
Kept context-switching between arxiv, OpenReview, GitHub, and HuggingFace for every paper, so I built this. Chrome extension + website with everything inline, plus citation graph + SPECTER2 neighbors. 3M papers, free, feedback welcome [P]
Streamline your research with a new Chrome extension and website that integrates 3M papers from arxiv, OpenReview, GitHub, and HuggingFace, including citation graphs and SPECTER2 neighbors, and provide feedback to improve it
Reddit r/MachineLearning
Up next
Beyond Big Vendors: ERP Systems Explained #shorts
Digital Transformation with Eric Kimberling
Watch →