Deloitte Data Analyst Interview Questions 1743734558
Deloitte Data Analyst Interview Questions 1743734558
(0-3 Years)
9-13 LPA
1. Data Extraction: SQL helps in retrieving relevant data using queries (e.g., SELECT *
FROM sales_data WHERE year = 2024;).
2. Data Cleaning & Transformation: Analysts use SQL functions like CASE,
COALESCE, TRIM, CAST, etc., to handle missing values, format data, and remove
duplicates.
3. Data Aggregation: SQL allows summarizing data using functions like SUM(), AVG(),
COUNT(), MAX(), and MIN().
4. Joins & Merging Tables: SQL enables combining data from multiple tables using
JOIN operations, helping analysts gather insights from different sources.
5. Filtering & Sorting Data: The WHERE, ORDER BY, and GROUP BY clauses allow
refining data based on specific conditions.
6. Creating Views & Reports: SQL can create views and stored procedures to
automate reporting processes and improve performance.
A Primary Key is a column (or a set of columns) in a table that uniquely identifies each
record.
Example:
Name VARCHAR(50),
Department VARCHAR(50)
);
Here, Emp_ID is the Primary Key, ensuring each employee has a unique identifier.
Foreign Key:
A Foreign Key is a column in one table that refers to the Primary Key in another table,
creating a relationship between them.
Example:
Emp_ID INT,
Order_Date DATE,
);
Here, Emp_ID in the Orders table is a Foreign Key referencing Emp_ID in the Employees
table. This ensures that an order is always linked to a valid employee.
2. LEFT JOIN (LEFT OUTER JOIN) – Returns all records from the left table and matching
records from the right table.
3. RIGHT JOIN (RIGHT OUTER JOIN) – Returns all records from the right table and
matching records from the left table.
4. FULL JOIN (FULL OUTER JOIN) – Returns all records when there is a match in either
table.
FROM Employees
FROM Employees
1 .INNER JOIN
Example:
FROM Employees
• Returns all records from the left table and matching records from the right table.
• If no match is found, NULL values appear for the right table’s columns.
Example:
FROM Employees
• Returns all records from the right table and matching records from the left table.
• If no match is found, NULL values appear for the left table’s columns.
Example:
FROM Employees
Scenario: Retrieves all orders, including those that aren’t linked to any employee.
• Returns all records from both tables, whether they match or not.
Example:
FROM Employees
5️ .CROSS JOIN
• Returns the Cartesian product of two tables (i.e., every row in the first table joins
with every row in the second table).
Example:
Scenario: If Employees has 5 rows and Orders has 4 rows, the result will have 5️ × 4 = 20
rows.
6️ .SELF JOIN
• Often used for hierarchical or relational comparisons (e.g., employees and their
managers).
Example:
FROM Employees E1
FROM Employees
GROUP BY Department
The GROUP BY statement is used to group rows with the same values in specified
columns and apply aggregate functions like SUM(), COUNT(), AVG(), MIN(), and MAX().
FROM Employees
GROUP BY Department;
FROM Orders
GROUP BY Customer_ID;
Groups orders by Customer ID and calculates the total spending per customer.
FROM Employees
GROUP BY Job_Title
Groups employees by job title and filters only those with an average salary above
70,000.
• Complex Data Retrieval: When direct JOINs are not feasible or when data needs
pre-processing before the main query.
Types of Subqueries
2. Multi-Row Subqueries – Return multiple values (used with IN, ANY, ALL).
The subquery calculates the average salary, and the main query retrieves
employees earning above that value.
The subquery groups employees by department, and the outer query filters
departments with an average salary above 5️0,000.
Example 3: Correlated Subquery (Finding employees with the highest salary in each
department)
FROM Employees E1
The subquery finds the max salary per department and compares it for each
employee.
An index is a database structure that improves query speed by allowing faster data
retrieval. It works like a book index—pointing directly to the required data instead of
scanning the entire table.
Benefits of Indexing:
• Speeds up SELECT queries by reducing row scans.
Drawbacks of Indexing:
Types of Indexes
5. Clustered Index – Determines the physical order of data in a table (only one per
table).
6. Non-Clustered Index – Stores index separately, allowing multiple indexes per table.
Advantages:
Disadvantages:
Normalization Forms
Customer_ID Customer_Name
1 Alice
2 Bob
Orders Table
Order_ID Customer_ID
101 1
102 2
Order_Details Table
101 Laptop 1
101 Mouse 2
102 Keyboard 1
Rules:
• Each column contains atomic (indivisible) values (no multiple values in a single
cell).
Significance: Eliminates duplicate data and ensures each column has atomic values.
• Must be in 1NF.
• All non-key attributes should depend entirely on the primary key (no partial
dependencies).
101 Alice
102 Bob
Products Table
P1 Laptop Electronics
P2 Keyboard Electronics
101 P1
102 P2
Rules:
• Must be in 2NF.
1 Alice 10 Sales
2 Bob 20 HR
1 Alice 10
2 Bob 20
Departments Table
10 Sales
20 HR
• Must be in 3NF.
101 C1
102 C2
103 C1
Courses Table
C1 Math Prof. A
C2 Science Prof. B
FROM Customers
FROM Customers_Orders_Products;
Trade-off: Faster read queries but higher storage and update complexity.
SELECT Name,
CASE
ELSE Salary
END AS Salary_Info
FROM Employees;
Summary
Window functions perform calculations across a set of table rows related to the
current row without collapsing the rows into a single output (unlike aggregate functions).
1. Ranking Functions
FROM Employees;
Ranks employees by salary within each department (same rank if salary is the
same).
FROM Employees;
Calculates the total salary for each department without grouping rows.
Use Case: Window functions are widely used in analytics, reporting, and ranking
operations.
Performance Slower (extra step to remove duplicates) Faster (no duplicate check)
Use Case When unique records are needed When performance matters
UNION
UNION ALL
When to Use?
15️. How Can You Optimize SQL Queries for Better Performance?
1. Use Proper Indexing
EXPLAIN ANALYZE
FROM Customers
);
EXISTS is more efficient than IN in large datasets.
FROM Employees
GROUP BY Department;
A Common Table Expression (CTE) is a temporary named result set that can be
referenced within a SQL query. It improves readability, modularity, and performance when
working with complex queries.
Syntax:
WITH CTE_Name AS (
FROM Table_Name
WHERE Condition
1. Improves Query Readability – Breaks down complex queries into smaller sections.
2. Avoids Repetition – Can be referenced multiple times in the query.
WITH High_Salary AS (
FROM Employees
Filters employees earning more than 70,000 and allows reuse of the result set.
WITH EmployeeHierarchy AS (
FROM Employees
UNION ALL
FROM Employees e
ACID properties ensure database transactions are reliable, consistent, and fault-
tolerant.
ACID
Description Example
Property
Transactions execute
Prevents race conditions in multi-user
Isolation independently without
environments.
interfering.
BEGIN TRANSACTION;
IF @@ERROR <> 0
ROLLBACK;
ELSE
COMMIT;
Ensures money is only transferred if both debit and credit operations succeed.
A Stored Procedure is a precompiled SQL script that can be executed multiple times with
parameters.
Syntax:
AS
BEGIN
END;
4. Reduced Network Traffic – Only procedure name & parameters are sent instead of
full query.
BEGIN TRY
BEGIN TRANSACTION;
UPDATE Accounts
WHERE Account_ID = 1;
UPDATE Accounts
WHERE Account_ID = 2;
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION;
END CATCH;
Ensures that if any update fails, the entire transaction is rolled back.
BEGIN TRANSACTION;
UPDATE Orders SET Quantity = Quantity - 1 WHERE Order_ID = 100;
IF @Error <> 0
BEGIN
ROLLBACK TRANSACTION;
END
ELSE
COMMIT TRANSACTION;
Checks for errors after each statement and rolls back if needed.
Best Practices: Always use transactions, try-catch blocks, and custom error messages
for robustness.
Removes Specific
Yes, with WHERE condition No, removes all rows
Rows?
Resets Identity
No Yes (resets AUTO_INCREMENT)
Column?
When to Use?
21. Explain the Concept of Database Views and Their Use Cases
What Is a View?
Syntax:
Types of Views
The LIKE operator is used to search for a specific pattern in a text column.
[^ ] Matches any character not inside brackets '[^A]%' → Doesn't start with A
Finds names that start with 'A' and have exactly 4 letters.
Finds names that start with 'A' and end with 'son'.
Aggregate functions perform calculations on a group of rows and return a single value.
FROM Employees
GROUP BY Department;
FROM Employees
GROUP BY Job_Title;
FROM Employees
GROUP BY Department;
Best Practices: Always use GROUP BY with aggregate functions to group data logically.
IGNORE 1 ROWS;
FROM 'C:\data\employees.csv'
Best Practices:
[^ ] Matches any character not inside brackets '[^A]%' → Doesn't start with A
Finds names that start with 'A' and end with 'son'.
Use Case: When filtering large datasets for customer names, email domains, or
product codes.
Aggregate functions compute a single value from a set of values. They are commonly used
with GROUP BY.
FROM Employees
GROUP BY Department;
FROM Employees
GROUP BY Job_Title;
FROM Employees
GROUP BY Department;
Use Case: Helps in sales analysis, performance metrics, and financial reporting.
IGNORE 1 ROWS;
FROM 'C:\data\employees.csv'
Best Practices:
✔ Validate data before importing/exporting.
✔ Use indexing after import for performance optimization.
✔ Back up databases before large-scale imports.
A transaction is a sequence of SQL operations that are executed as a single unit of work.
A transaction ensures that either all operations are completed successfully, or none of
them are applied to maintain database integrity.
Consistency Ensures database remains in a valid state before and after the transaction.
START TRANSACTION;
Ensures money is deducted from one account and added to another only if both
operations succeed.
START TRANSACTION;
IF @@ERROR <> 0
ROLLBACK;
ELSE
COMMIT;
SQL security ensures only authorized users can access or modify the database,
protecting sensitive data from unauthorized access or breaches.
1. Creating Users
2. Granting Privileges
3. Revoking Privileges
WITH RankedProducts AS (
SELECT
p.Category,
p.ProductName,
FROM Sales s
FROM RankedProducts
Explanation of Components
Component Explanation
Use Case:
This query is used in e-commerce analytics to identify top-selling products per
category.