Data Analyst SQL Interview Questions | EY (Ernst & Young) | Shared By An Experienced Data Analyst

This article tackles common SQL Interview Questions asked by EY, offering detailed solutions and explanations to help aspiring data analysts prepare effectively. These SQL Interview Questions, shared by an experienced Data Analyst at EY, cover a range of SQL concepts crucial for success in the interview process.

SQL Interview Questions For data analyst

There are a total of 10 SQL queries with their solution that were asked in the interviews of Data Analyst Post at EY Company. EY (Ernst & Young) is a global leader in professional services, known as one of the “Big Four” accounting organizations alongside Deloitte, KPMG, and PwC.

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 fetch the top 5 employees with the highest salaries from an Employees table

SELECT EmployeeID, Name, Salary
FROM Employees
Order by salary desc limit 5

Db-fiddle Link: https://www.db-fiddle.com/f/ezoQvyQwtqYzeYxrg7DDPp/0

Write a query to list all records in the Orders table where the delivery_date is NULL

SELECT *
FROM Orders
WHERE delivery_date IS NULL;

Db-fiddle Link: https://www.db-fiddle.com/f/bQuPJaJM3A5vCbVuK5SFdy/0

Write a query to calculate the total sales and average discount offered in each product category from the Products table

SELECT category_name, SUM(price*quantity) as total_sale, round(avg(discount_percentage),2) as discount_offered
FROM Sales
GROUP BY category_name;

Db-fiddle Link: https://www.db-fiddle.com/f/e6AR8NgeQVSpUvnKiRggzh/0

Retrieve project details along with the names of project managers for all projects where the status is “Completed,” using a join between the Projects and Employees tables

SELECT 
	p.project_id,
    p.project_name,
    p.project_manager_id,
    p.status,
    e.name as project_manager
FROM Projects p left join Employees e on p.project_manager_id = e.employee_id
WHERE status = 'Completed'

Db-fiddle Link: https://www.db-fiddle.com/f/7d11oXtYacx2LFHQLLdi7x/0

Write a query to fetch all invoices in the Invoices table where the due date is more than 15 days past the invoice date.

SELECT *
FROM Invoices
WHERE due_date > invoice_date + 15;

Db-fiddle Link: https://www.db-fiddle.com/f/jNt6Z71D7ZGxMSQ2NgThiC/0

Write a query to identify suppliers from the Suppliers table whose total supplied quantity exceeds 10,000 units, grouped by supplier_id.

SELECT 
	s.supplier_id,
    s.supplier_name,
    sum(sr.quantity_supplied) as quantity_supplied
FROM Suppliers s INNER JOIN Supply_Records sr on s.supplier_id = sr.supplier_id
GROUP BY s.supplier_id
HAVING quantity_supplied > 10000;

Db-fiddle Link: https://www.db-fiddle.com/f/xANZi6gDXbGtB5zeV656Bn/0

How would you find duplicate entries in the Transactions table based on both transaction_id and customer_id? Write a query to display these duplicate rows.

SELECT transaction_id, customer_id, COUNT(*) AS duplicate_count
FROM Transactions
GROUP BY transaction_id, customer_id
HAVING COUNT(*) > 1;

Db-fiddle Link: https://www.db-fiddle.com/f/MxcEqPENcZbgA6ViJ69Q9/0

Write a query to rank products in each category by their total sales revenue using a ranking function.

Select 
	p.product_id,
	p.product_name,
    p.category_id,
    sum(oi.quantity*oi.price) as total_sale,
    rank() over(partition by p.category_id order by sum(oi.quantity*oi.price) desc ) as sale_rank
FROM Products p inner join Order_Items oi
on p.product_id = oi.product_id
group  by product_id, p.product_name, p.category_id;

Db-fiddle Link: https://www.db-fiddle.com/f/93vcg26uxGqEaijxWXkvbw/0

Write a query to find all customers in the Customers table who have not placed an order in the last 6 months.

select distinct o.customer_id, c.customer_name 
from Orders o inner join Customers c on o.customer_id = c.customer_id
where order_date not between 
        (select max(order_date) from Orders) 
        and 
        (select DATE_SUB(max(order_date), INTERVAL 6 MONTH) from Orders)
       or order_date is null;

Db-fiddle Link: https://www.db-fiddle.com/f/2Ar7RoeN65VRf8C7SS24Vo/0

Write a query to update the salary column in the Employees table to increase by 10% for employees in the “Marketing” department.

select 
	e.employee_id,
    e.employee_name,
    e.employee_name,
    case
    	when d.Department_name = 'Marketing' then round(salary*1.1,2)
        else salary
    end as salary,
    d.department_name
from Employees e join Departments d on e.department_id = d.department_id
order by d.department_name;

Db-fiddle Link: https://www.db-fiddle.com/f/niQryWFvYHkKg5C6gsqwuv/1

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:-

Spread the love