9 Recently Asked Google SQL Interview Questions from Google Data Science & Data Analyst Interviews
DataLemur ?? (Ace the SQL & Data Interview)
Practice 200+ FAANG SQL & Data Interview questions! Made by Nick Singh (Ex-FB & Author of Ace the Data Interview ??)
If you've got an upcoming Data Science or Data Analyst interview at Google, then expect to face multiple tricky SQL interview questions as part of the process. But have no fear – we'll cover 9 real Google SQL Interview questions in this article, along with some SQL interview prep tips, so that you're not caught off-guard during the interview!
Google SQL Question #1: Odd and Even Measurements
Assume you're given a table with measurement values obtained from a Google sensor over multiple days with measurements taken multiple times within each day. Write a SQL query to calculate the sum of odd-numbered and even-numbered measurements separately for a particular day and display the results in two different columns.
You can solve this same Google SQL problem interactively on DataLemur:
Solution: We can use the ROW_NUMBER() window function to label each row with a sequential ranking, and then use the MOD() function to determine if the row is even or odd:
WITH ranked_measurements AS (
SELECT
CAST(measurement_time AS DATE) AS measurement_day,
measurement_value,
ROW_NUMBER() OVER (
PARTITION BY CAST(measurement_time AS DATE)
ORDER BY measurement_time) AS measurement_num
FROM measurements
)
SELECT
measurement_day,
SUM(measurement_value) FILTER (WHERE measurement_num % 2 != 0) AS odd_sum,
SUM(measurement_value) FILTER (WHERE measurement_num % 2 = 0) AS even_sum
FROM ranked_measurements
GROUP BY measurement_day;
Google SQL Question #2: What is a CTE, and when would you use one?
This interview question is just trying to test if you know the difference between a CTE and Subquery. Even if you can't explain it will, they are just trying to make sure you know how to right modular SQL code, and weed you any candidates who nest 37 sub-queries inside on another.
If you need a refresher, check out this interactive SQL tutorial on CTEs vs. Subqueries:
领英推荐
Google SQL Question #3: Median Google Search Frequency
Google's marketing team needs to find the median number of searches a person made last year. However, at Google scale, analyzing 2 trillion searches is too costly. Luckily, you have access to the summary table which tells you the number of searches made last year and how many Google users fall into that bucket.
Write a SQL query to report the median of searches made by a user (round the median to one decimal point).
In the above example, we get a median of 2.5 searches per user by expanding the search_frequency table which is 1, 1, 2, 2, 3, 3, 3, 4.
To run your SQL query solution directly in the browser, solve this Google Interview Question on DataLemur!
Want To Practice The Rest of the Google SQL Interview Questions?
You'll find the rest of the Google SQL interview questions on DataLemur's blog post 11 Google SQL Interview Questions (Updated 2024).
It can also be helpful to practice other FAANG SQL Interview questions on DataLemur, because at the end of the day, Google doesn't do things ~too~ differently from other competitive tech companies like Facebook and Amazon.
Founder: DataLemur.com (SQL Interview Prep) ? Author: Ace the Data Science Interview ? Ex-Facebook ? 160K+ follow me on LinkedIn for Data/SQL/Career tips!
11 个月great Google SQL interview tips here!