
This article is about the SQL Interview Questions asked by Walmart for their Data Analyst post. It offers detailed solutions and explanations to help you prepare data analysts effectively. These SQL Interview Questions, shared by an experienced Data Analyst, cover a range of SQL concepts crucial for success in the interview process.
SQL Interview Questions For data analyst
There are a total of 3 SQL queries with their solution that were asked in the interviews for the Data Analyst Post at Walmart. Walmart is an American multinational retail corporation that operates a chain of hypermarkets, discount department stores, and grocery stores in the United States and 23 other countries.
Note: To help you better understand the SQL solutions presented in this article, we’ve used db-fiddle. This free online tool allows you to execute SQL queries directly against a database and see the results instantly. For each question, you’ll find a link to a corresponding db-fiddle, where you can explore the data, modify the queries, and experiment to solidify your understanding.
SQL Interview Questions Solutions
Write a query to retrieve the second-highest salary within a department. You can use functions like ROW_NUMBER() or DENSE_RANK() for this.
select *
FROM(
SELECT
e.employee_id,
e.employee_name,
d.department_id,
d.department_name,
e.salary,
RANK() OVER(PARTITION BY d.department_id ORDER BY e.salary DESC) AS salary_rank
FROM Employees e
LEFT JOIN Departments d ON e.department_id = d.department_id) sal
where salary_rank = 2;
Db-fiddle Link: https://www.db-fiddle.com/f/nDanCgDc8dhQJWzmX3Cv8s/0
Create a query to calculate the daily transaction count per user, utilizing GROUP BY and COUNT() for aggregation.
SELECT
user_id,
user_name,
COUNT(*) AS transaction_count
FROM Transactions INNER JOIN Users USING(user_id)
GROUP BY user_id;
Db-fiddle Link: https://www.db-fiddle.com/f/99faQQr3dez6VWJTvXJtZn/0
Write a query to identify projects with the highest budget-per-employee ratio by joining two tables: projects and employees. This will test your ability to perform complex joins and aggregations.
SELECT
project_id,
project_name,
budget,
no_of_emp,
round((budget / no_of_emp),2) AS ratio
FROM
(
SELECT
p.project_id,
p.project_name,
p.budget,
COUNT(e.employee_id) as no_of_emp
FROM Projects p LEFT JOIN Employees e on p.project_id = e.project_id
GROUP BY p.project_id, p.project_name) data
ORDER BY ratio DESC
LIMIT 1;
Db-fiddle Link: https://www.db-fiddle.com/f/an2pDriLARsihEqbMCfSK1/0
For More SQL Interview Questions Follow Us On:
Thank you for reading! We hope this article has been helpful in your SQL Interview Questions preparation. If you found it valuable, please share it with your network.
Also Read:-
- Python Practice Questions & Solutions Day 5 of Learning Python for Data Science
- Day 5 of Learning Python for Data Science: Data Types, Typecasting, Indexing, and Slicing
- Python Practice Questions & Solutions Day 4 of Learning Python for Data Science
- Day 4 of Learning Python for Data Science
- Practice Questions and Answers for Day 3 of Learning Python for Data Science
Hi, I’m Anuja Bisht, a recent graduate from DU SOL with a passion for digital marketing. I created Curious Club (curiousclub.in) to help you stay ahead of the job curve. My goal is to provide you with the latest job updates and resources, empowering you to land your dream career.