Data Science SQL Interview Question Walkthrough (real interview style) | SQL Sundays #7

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

Key Takeaways

This video demonstrates a data science SQL interview question walkthrough, specifically finding the minimum, average, and maximum rental price for each review qualification category on Airbnb, using SQL queries with case statements and common table expressions (CTEs).

Full Transcript

and we're back with another sequel sunday let's jump into it okay so this question that we have here today is from airbnb find the minimum average and maximum rental price for each review qualification category the review qualification category is a classification applied to each rental property based on the number of reviews the property has okay so it's defined below like this cool okay let's look at the table here so okay airbnb search details this is a big table uh lots of things going on let's see [Music] so we want to look at the review qualification so we're looking at the number of reviews the property has so we're basing these um classification on that so let's see if one of these columns gives us a hint about the number of views okay okay bathroom blah blah blah blah oh okay cool so number of views is literally here this is really nice i actually thought that it would be more complex since you know maybe it would be like each review and you had to aggregate it but it has a number of views here for us that's great so let us have a plan and see what we're gonna do so finally we want our expected output to look like so reviews qualification oops slice spelling area there reviews qualification um let's comment this out main price average price and max price max price cool all right so what assumptions do i have okay so first assumption is that all the values are going to be an integer so i'm going to assume that we don't have any null values here um yeah so i'm going to assume that it's gonna be positive integers for this what other things do i have i think that's about it cool all right we can go on to right what we're gonna do so first thing we're gonna do is do the classification and to do this we're going to use case 1 statements should be pretty straightforward and then after we do that i am going to um just do aggregation so group by the rental price oops not rental price um group by qualification category and then aggregate min average and maximum price cool all right let's do this query so from airbnb search details a case when what is it called again number of reviews number of reviews is equal to zero then no one number of reviews is oops nice between one and five then few when number of reviews between 6 and 15 then [Music] [Applause] number of reviews between 16 and 40 than many when number of reviews actually i can just do this else a lot because we're assuming since um it's not going to be null and it's going to be positive so this should catch everything else that's more than 40 reviews okay so end as what is it called again oh yeah reviews qualification cool um so now we can do like a sub query for this uh like nested but i always prefer to use ct's because i just think it's a lot clearer for the interviewer to read and also for you to not get confused oh oops one thing one thing one thing uh we also need a price right because we are aggregating by price cool all right so let's call this with um [Music] class with reviews as here and we can do from reviews now we're going to group by qualification category so let's write the select statement first select reviews qualification um what is it minimum so minimum of price as bin price as price as average price and max price x max price as uh max price cool and then we're gonna group by one let's see let's see looks good to me fingers crossed ran our code oh no what happened oh oh my god i forgot to write the select statement whoops okay rookie mistake okay this should work now yay okay good we got this right all right is there any other way that we can optimize things you could use a sub query like just nest it and not save it as a table so that would optimize actually no i don't would that even optimize things um that's a good point let's check that out so let's see like ct versus sub query performance okay so they're actually the same since both provide the same information to query optimizer use more than once could be easily identifying calculators out could then be stored okay so they're actually the same times performance so i don't think we can actually optimize it based upon that and i don't think that we can optimize it in any other way either okay so they did us a sub query here um yeah it's pretty much the same solution it's just the subquery i generally just prefer using cts as opposed to subqueries we're done with this episode and feel free to check out strata scratch i will link it below as well alright see you guys next time suddenly you're nowhere to be found i turn around and everything has changed looking for a way to work it out i'm trying to find some peace [Music] is [Music] again [Music] everything we wanted turned to gold the past we chose the future on our side [Music] and the writing on the [Music] can you hear me we'll meet again [Music] dark for the sunrise clouds for a blue sky space for the traveling star [Music] strong from the inside you're still my lifeline i feel you wherever you the oak are where i met you and the writing on the statue i still remember happy words [Music] follow me again you

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 · 22 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
10 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
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 teaches how to write SQL queries to analyze data, specifically finding the minimum, average, and maximum rental price for each review qualification category on Airbnb, and how to optimize queries for performance. The video uses a real interview style to demonstrate the thought process and query writing skills required for data science interviews.

Key Takeaways
  1. Define the problem and identify the relevant data
  2. Write a SQL query using case statements to classify review qualification categories
  3. Use a common table expression (CTE) to simplify the query and improve readability
  4. Optimize the query for performance by comparing CTE and subquery approaches
  5. Test and refine the query to ensure accurate results
💡 Using CTEs can improve query readability and maintainability, but may not always optimize performance. It's essential to test and compare different query approaches to ensure optimal results.

Related Reads

Up next
The Secret Methodology Structure Q1 Reviewers Expect (But Journals Never Tell You)
Academic English Now
Watch →