A Data Analyst who doesn't know SQL is like a solider who can't shoot a gun: utterly useless. Data Analysts are expected to pull and manipulate data from large datasets and generate valuable insights, and the workhorse behind that is usually SQL. That's why most companies, especially competitive big-tech companies like Amazon and Facebook, ask Data Analysts SQL interview questions. So, to help you prepare, scroll down to solve 15 SQL interview questions for Data Analysts!
Your team at JPMorgan Chase is preparing to launch a new credit card, and to gain some insights, you're analyzing how many credit cards were issued each month.
Write a query that outputs the name of each credit card and the difference in the number of issued cards between the month with the highest issuance cards and the lowest issuance. Arrange the results based on the largest disparity.
Table:
Column Name | Type |
---|---|
issue_month | integer |
issue_year | integer |
card_name | string |
issued_amount | integer |
Example Input:
card_name | issued_amount | issue_month | issue_year |
---|---|---|---|
Chase Freedom Flex | 55000 | 1 | 2021 |
Chase Freedom Flex | 60000 | 2 | 2021 |
Chase Freedom Flex | 65000 | 3 | 2021 |
Chase Freedom Flex | 70000 | 4 | 2021 |
Chase Sapphire Reserve | 170000 | 1 | 2021 |
Chase Sapphire Reserve | 175000 | 2 | 2021 |
Chase Sapphire Reserve | 180000 | 3 | 2021 |
Example Output:
card_name | difference |
---|---|
Chase Freedom Flex | 15000 |
Chase Sapphire Reserve | 10000 |
You can solve this JPMorgan Chase SQL problem interactively, and get the full solution explanation.
Answer: DDL (Data Definition Language) is used to define, modify, and delete database objects such as tables, indexes, and constraints. In contrast, DML (Data Manipulation Language) is used to manipulate the data stored in the database, such as inserting, updating, deleting, and querying data.
You're trying to find the mean number of items per order on Alibaba, rounded to 1 decimal place using tables which includes information on the count of items in each order ( table) and the corresponding number of orders for each item count ( table).
Table:
Column Name | Type |
---|---|
item_count | integer |
order_occurrences | integer |
Example Input:
item_count | order_occurrences |
---|---|
1 | 500 |
2 | 1000 |
3 | 800 |
4 | 1000 |
There are a total of 500 orders with one item per order, 1000 orders with two items per order, and 800 orders with three items per order.
Example Output:
mean |
---|
2.7 |
You can solve this Alibaba SQL problem interactively, and get the full solution explanation.
Enjoyed this one? p.s. here's more Alibaba SQL Interview Questions to practice!
Answer: A primary key is a unique identifier for each record in a database table. It ensures that each row in the table is uniquely identified and allows for efficient data retrieval and indexing.
Intuit provides a range of tax filing products, including TurboTax and QuickBooks, available in various versions.
Write a query to determine the total number of tax filings made using TurboTax and QuickBooks. Each user can file taxes once a year using only one product.
If you find this question interesting, you may also want to try a similar question called Laptop vs Mobile Viewers!
Table:
Column Name | Type |
---|---|
filing_id | integer |
user_id | varchar |
filing_date | datetime |
product | varchar |
Example Input:
filing_id | user_id | filing_date | product |
---|---|---|---|
1 | 1 | 4/14/2019 | TurboTax Desktop 2019 |
2 | 1 | 4/15/2020 | TurboTax Deluxe |
3 | 1 | 4/15/2021 | TurboTax Online |
4 | 2 | 4/07/2020 | TurboTax Online |
5 | 2 | 4/10/2021 | TurboTax Online |
6 | 3 | 4/07/2020 | TurboTax Online |
7 | 3 | 4/15/2021 | TurboTax Online |
8 | 3 | 3/11/2022 | QuickBooks Desktop Pro |
9 | 4 | 4/15/2022 | QuickBooks Online |
Example Output:
turbotax_total | quickbooks_total |
---|---|
7 | 2 |
You can solve this Intuit SQL problem interactively AND see alternate solutions, and get the full solution explanation.
Looking for more Intuit SQL Interview Questions? Check out our Intuit SQL Interview Guide for access to even more questions and solutions!
Answer: INNER JOIN returns only the rows that have matching values in both tables involved in the join, while LEFT JOIN returns all the rows from the left table and the matched rows from the right table, with NULL values for unmatched rows on the right.
Want to practice SQL JOINS? Try our SQL JOINS Tutorial with Practice Exercises page from our SQL Tutorial guide.
As a Data Analyst on Snowflake's Marketing Analytics team, you're analyzing the CRM to determine what percent of marketing touches were of type "webinar" in April 2022. Round your percentage to the nearest integer.
Did you know? Marketing touches, also known as touch points are the brand's (Snowflake's) point of contact with the customers, from start to finish.
Table:
Column Name | Type |
---|---|
event_id | integer |
contact_id | integer |
event_type | string |
event_date | date |
Example Input:
event_id | contact_id | event_type | event_date |
---|---|---|---|
1 | 1 | webinar | 4/17/2022 |
2 | 1 | trial_request | 4/23/2022 |
3 | 1 | whitepaper_download | 4/30/2022 |
4 | 2 | handson_lab | 4/19/2022 |
5 | 2 | trial_request | 4/23/2022 |
6 | 2 | conference_registration | 4/24/2022 |
7 | 3 | whitepaper_download | 4/30/2022 |
8 | 4 | trial_request | 4/30/2022 |
9 | 4 | webinar | 5/14/2022 |
Example Output:
webinar_pct |
---|
13 |
You can solve this Snowflake SQL problem interactively, and get the full solution explanation.
Enjoyed this one? p.s. here's more Snowflake SQL Interview Questions to practice!
Answer: NULL values in SQL represent missing or unknown data. They can be handled using functions like IS NULL and IS NOT NULL to filter rows with NULL values or using functions like COALESCE or IFNULL to replace NULL values with specified default values.
As a data analyst on the Oracle Sales Operations team, you are given a list of salespeople’s deals, and the annual quota they need to hit.
Write a query that outputs each employee id and whether they hit the quota or not ('yes' or 'no'). Order the results by employee id in ascending order.
Definitions:
Table:
Column Name | Type |
---|---|
employee_id | integer |
deal_size | integer |
Table:
Column Name | Type |
---|---|
employee_id | integer |
quota | integer |
Example Input:
employee_id | deal_size |
---|---|
101 | 400000 |
101 | 300000 |
201 | 500000 |
301 | 500000 |
Example Input:
employee_id | quota |
---|---|
101 | 500000 |
201 | 400000 |
301 | 600000 |
Example Output:
employee_id | made_quota |
---|---|
101 | yes |
201 | yes |
301 | no |
You can solve this Oracle SQL problem interactively, and get the full solution explanation.
Enjoyed this one? p.s. here's more Oracle SQL Interview Questions to practice!
Answer: Data normalization is the process of organizing data in a database to minimize redundancy and dependency by dividing large tables into smaller tables and defining relationships between them. It ensures data integrity, reduces data duplication, and improves database efficiency.
You are tasked with identifying Subject Matter Experts (SMEs) at Accenture based on their work experience in specific domains. An employee qualifies as an SME if they meet either of the following criteria:
Write a query to return the employee IDs of all the subject matter experts at Accenture.
Assumption:
Table:
Column Name | Type |
---|---|
employee_id | integer |
domain | string |
years_of_experience | integer |
Example Input:
employee_id | domain | years_of_experience |
---|---|---|
101 | Digital Transformation | 9 |
102 | Supply Chain | 6 |
102 | IoT | 7 |
103 | Change Management | 4 |
104 | DevOps | 5 |
104 | Cloud Migration | 5 |
104 | Agile Transformation | 5 |
Example Output:
employee_id |
---|
101 |
102 |
You can solve this Accenture SQL problem interactively, and get the full solution explanation.
Answer: A foreign key is a column or set of columns in a table that references the primary key or unique key of another table. It establishes a relationship between the two tables, enforcing referential integrity and maintaining consistency in the data.
Given the reviews table, write a query to retrieve the average star rating for each product, grouped by month. The output should display the month as a numerical value, product ID, and average star rating rounded to two decimal places. Sort the output first by month and then by product ID.
Table:
Column Name | Type |
---|---|
review_id | integer |
user_id | integer |
submit_date | datetime |
product_id | integer |
stars | integer (1-5) |
Example Input:
review_id | user_id | submit_date | product_id | stars |
---|---|---|---|---|
6171 | 123 | 06/08/2022 00:00:00 | 50001 | 4 |
7802 | 265 | 06/10/2022 00:00:00 | 69852 | 4 |
5293 | 362 | 06/18/2022 00:00:00 | 50001 | 3 |
6352 | 192 | 07/26/2022 00:00:00 | 69852 | 3 |
4517 | 981 | 07/05/2022 00:00:00 | 69852 | 2 |
Example Output:
mth | product | avg_stars |
---|---|---|
6 | 50001 | 3.50 |
6 | 69852 | 4.00 |
7 | 69852 | 2.50 |
You can solve this Amazon SQL problem interactively, and get the full solution explanation.
Enjoyed this one? p.s. here's more Amazon SQL Interview Questions to practice!
Answer: A stored procedure is a precompiled set of SQL statements that are stored in the database and can be executed repeatedly by calling the procedure name. It can contain DML and DDL statements, accept input parameters, and return output values. Unlike functions, stored procedures do not necessarily return a value.
This is the same question as problem #5 in the SQL Chapter of Ace the Data Science Interview!
Assume that you are given the table below-containing information on various orders made by eBay customers. Write a query to obtain the user IDs and number of products purchased by the top 3 customers; these customers must have spent at least $1,000 in total.
Output the user id and number of products in descending order. To break ties (i.e., if 2 customers both bought 10 products), the user who spent more should take precedence.
Table:
Column Name | Type |
---|---|
transaction_id | integer |
product_id | integer |
user_id | integer |
spend | decimal |
Example Input:
transaction_id | product_id | user_id | spend |
---|---|---|---|
131432 | 1324 | 128 | 699.78 |
131433 | 1313 | 128 | 501.00 |
153853 | 2134 | 102 | 1001.20 |
247826 | 8476 | 133 | 1051.00 |
247265 | 3255 | 133 | 1474.00 |
136495 | 3677 | 133 | 247.56 |
Example Output:
user_id | product_num |
---|---|
133 | 3 |
128 | 2 |
102 | 1 |
You can solve this eBay SQL problem interactively, and get the full solution explanation.
Enjoyed this one? p.s. here's more eBay SQL Interview Questions to practice!
The best way to prepare for the SQL interview is to practice, practice, practice. Besides solving the earlier SQL interview questions, you should also solve the 200+ SQL coding questions which come from companies like FAANG tech companies and tech startups.
Each exercise has hints to guide you, step-by-step solutions and best of all, there is an interactive coding environment so you can right online code up your SQL query and have it checked.
However, if your SQL skills are weak, forget about going right into solving questions – refresh your SQL knowledge with this DataLemur SQL Tutorial.
To prepare for the Data Analyst interviews read the book Ace the Data Science Interview because it's got: