SQL questions
SQL questions
in/dumdCXC7
2. Employees earning > managers: https://Inkd.in/dKqcFmzY
3. Duplicate emails: https://lnkd.in/dJSYfs89
4. Customers who never order : https://lnkd.in/dPZPAKFf
5. Delete duplicate emails: https://lnkd.in/dEKnD9s3
6. Rising temperature: https://lnkd.in/dyZvVYvP
7. Employee bonus: https://Inkd.in/d9iTXt-V
8. Find customer referee : https://lnkd.in/d5cXjXdb
10. Big countries: https://lnkd.in/dAnS54qK
11. Classes more than 5 students : https://lnkd.in/dfrUiutd
12. Sales person: https://lnkd.in/dwRnf5Df
13. Triangle judgement: https://lnkd.in/dwzD-hFn
14. Biggest single number: https://lnkd.in/d4F5zHDs
15. Not boring movies: https://lnkd.in/d5w8_z65
16. Swap salary: https://lnkd.in/dnbCtecM
18. Product sales analysis 1: https://lnkd.in/dRj3EBuK
19. Project employees 1: https://lnkd.in/dvGHsbKQ
20. Sales analysis III : https://lnkd.in/d_y_rxPh
3- Running sales over months, rolling N months sales, within each category etc.
4- Pivot rows to columns, eg: year wise sales for each category in separate columns, etc
Deloitte:
1. Amazon
Link: https://lnkd.in/dC64SAXX
2. Google
Link: https://lnkd.in/dmex67dV
3. Goldman Sachs
Link: https://lnkd.in/dKn2EUPv
4. Microsoft
Link: https://lnkd.in/dUWRbi-8
5. Uber
Link: https://lnkd.in/dvt8RpGg
hashtag
#Complex Joins:
hashtag
#Question: "You need to produce a report showing all customers who have not made any purchases
in the last year. How would you structure your SQL query?"
hashtag
#Purpose: Tests ability to perform LEFT JOINs and use conditions to filter data.
Data Cleaning:
hashtag
#Question: "How would you identify and update or remove records that contain null values in critical
fields in the database?"
hashtag
#Purpose: Tests skills in data integrity checks and UPDATE/DELETE operations.
Window Functions:
hashtag
#Question: "Write a SQL query to rank employees within each department based on their salary."
hashtag
#Purpose: Assesses knowledge of window functions like RANK() or DENSE_RANK().
SQL Questions
1. You have a table Transactions with columns TransactionID, CustomerID, Date, and Amount. Write
a query to calculate the cumulative revenue per customer for each month in the last year.
2. A table Production contains columns PlantID, Date, and Output. Write a query to identify the plants
that consistently exceeded their daily average output for at least 20 days in a given month.
3. In a table EmployeeAttendance with columns EmployeeID, Date, and Status (values: ‘Present’,
‘Absent’), write a query to find employees with the highest consecutive absences in the last quarter.
4. What are the pros and cons of using indexes in SQL, and when would you avoid using them?
5. Explain the differences between window functions and aggregate functions with examples.
Python Questions
6. Write a Python script to merge multiple CSV files from a directory into a single file and perform
basic data cleaning.
7. Given a list of dictionaries, write a Python program to group the data by a specific key and
calculate summary statistics for the grouped data.
8. Explain the difference between a list, a tuple, and a dictionary in Python, and provide examples of
their usage.
9. Write a Python function to automate the generation of monthly reports from a dataset stored in an
Excel file.
Power BI Questions
10. How would you create a dashboard in Power BI to track the operational efficiency of production
plants?
11. Explain how you would handle a situation where the data source refresh in Power BI is causing
delays.
12. What is the difference between row-level security and role-level security in Power BI?
13. How would you use Power BI to visualize trends and outliers in daily sales data?
14. Discuss how you would create a calculated measure to show YoY (Year-over-Year) growth in
Power BI.
General Questions
15. Share an example where your data-driven insights helped solve a business problem or improve a
process.
16. How do you prioritize tasks and manage deadlines in a high-pressure environment?
17. Why do you want to join EXL, and how do you see your expertise aligning with their vision?
🔹SQL35: X https://shorturl.at/rcVxq
Medium Level:
1 How do you identify duplicate records in a table?
1️⃣
2️⃣How can you delete duplicates while keeping just one entry?
3️⃣What's the difference between UNION and UNION ALL?
4️⃣When should you use RANK, ROW_NUMBER, and DENSE_RANK?
5️⃣How do you find records in one table that don’t exist in another?
6️⃣How do you retrieve the second-highest salary for each department?
7️⃣How do you find employees earning more than their manager?
8️⃣What’s the key difference between INNER JOIN and LEFT JOIN?
9️⃣How would you swap gender values (M ↔ F) in a table using SQL?
🔟 How do different types of joins impact the number of records in the output?
➤ 𝗪𝗶𝗻𝗱𝗼𝘄 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀
➤ 𝗦𝘂𝗯𝗾𝘂𝗲𝗿𝗶𝗲𝘀
1. Find employees earning more than the average salary in their department.
2. Retrieve customers who have placed more than 5 orders.
3. List products that have never been ordered.
4. Identify the second highest salary in the company using a subquery.
5. Find departments where all employees earn above a specific threshold.
➤ 𝗔𝗴𝗴𝗿𝗲𝗴𝗮𝘁𝗲 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀
SQL Questions
1. Calculate the cancellation rate for each room type over the last 6 months, considering only
bookings with a minimum stay of 2 nights.
2. Determine the average conversion rate (confirmed bookings vs. search events) for users grouped
by their country and device type.
3. Identify properties that have consistently underperformed compared to the average booking rate
of their region over the last 12 months.
4. Detect instances of demand surge where the number of bookings in an hour exceeds the hourly
average by more than 50%.
5. What challenges might arise when querying sharded databases, especially for calculating global
metrics like average booking rates?
6. Explain how you would handle booking timestamps originating from different time zones when
querying for global daily booking patterns.
7. how would you balance normalization for data integrity and denormalization for query
performance?
8. If two systems simultaneously update the same booking record, what mechanisms would you use
in SQL to prevent data conflicts and ensure consistency?
9. Explain the scenarios where window functions outperform traditional group-by clauses in SQL.
Guesstimate Questions
1. Estimate the total number of hotel bookings made globally in a day on Booking.com
. Explain the factors and assumptions you would consider to arrive at your estimate.
2. How many unique users do you think search for flights on Booking.com
in a month? Provide a structured approach to your calculation.
SQL Questions
1️⃣Write a query to find the cumulative revenue by month for each product category in a sales
table.
2️⃣How would you retrieve the top 5 products by sales volume, excluding any products that had
zero sales in the past 3 months?
3️⃣Given a table of customer transactions, identify all customers who made purchases in two or
more consecutive months.
4️⃣Write a query to calculate the retention rate of users on a monthly basis.
5️⃣Find the nth highest salary from an employee table, where n is passed dynamically to the
query.
6️⃣Explain how indexing works in SQL and how to decide which columns should be indexed for
optimal performance.
7️⃣Describe the differences between LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN, and when
to use each in a complex query.
8️⃣What is the difference between HAVING and WHERE clauses in SQL? When would you use
each?
Input Table:
• transactions table:
- transaction_id (integer)
- account_id (integer)
- amount (decimal)
- transaction_type (varchar)
Input Table:
• transactions table:
- transaction_id (integer)
- user_id (integer)
- transaction_date (date)
- amount (decimal)
Input Table:
• payments table:
- payer_id (integer)
- recipient_id (integer)
- amount (integer)
Input Tables:
• transactions table:
- transaction_id (integer)
- user_id (integer)
- transaction_date (date)
- transaction_type (varchar)
- amount (decimal)
• users table:
- user_id (integer)
- username (text)
- is_fraudulent (boolean)
• Transactions table:
- transaction_id (integer)
- user_id (integer)
- transaction_date (date)
- transaction_amount (decimal)
SQL Questions:
SQL Questions:
You’re a data analyst at Airbnb and you’ve been tasked with retrieving housing data from specific
cities. You want to find all Airbnb listings in San Francisco and New York that have at least 10
reviews and an average rating equal to or above 4.5.
Tables:
• listings: listing_id (integer), name (string), city (string), reviews_count (integer)
• reviews: listing_id (integer), review_id (integer), stars (integer), submit_date (date)
2. Find the Average Number of Guests per Booking in Each City for Airbnb
As an analyst at Airbnb, one of the most useful insights you could provide would be to understand
the average number of guests per booking across locations. For this question, we would like you to
write a SQL query that will find the average number of guests per booking in each city.
Tables:
• bookings: booking_id (integer), property_id (integer), guests (integer), booking_date (date)
• properties: property_id (integer), city (string)
The scenario is that Airbnb wants to analyze the click-through conversion rates (CTRs) of their
listings. The CTR is calculated by dividing the number of bookings by the number of listing views,
giving a proportion of views that resulted in a booking.
Tables:
• listing_views: view_id (integer), user_id (integer), visit_date (date), listing_id (integer)
• bookings: booking_id (integer), user_id (integer), booking_date (date), listing_id (integer)
The strategy team in Airbnb is trying to analyze the impact of Covid-19 during 2021. To do so, they
need you to write a query that outputs the average vacant days across the AirBnbs in 2021. Some
properties have gone out of business, so you should only analyze rentals that are currently active.
Round the results to a whole number.
Assumptions:
• is_active field equals 1 when the property is active, and 0 otherwise.
• In cases where the check-in or check-out date is in another year other than 2021, limit the
calculation to the beginning or end of the year 2021 respectively.
• A listing can be active even if there are no bookings throughout the year.
Tables:
• bookings: listing_id (integer), checkin_date (date), checkout_date (date)
• listings: listing_id (integer), is_active (integer)
1, A, 2
2, B, 3
3, C, 4
30000
30000
What would be the result of row number, rank, and dense rank ?
8. Find all the students who either are male or live in Mumbai ( have Mumbai as a part of their
address).
9. Suppose there are two columns in employee table i.e. emp id and email.Get all the unique
domains like gmail.com, yahoo.com, outlook.com, etc.
10. Can you join two table without any common column?
11. Give the output for the following
SELECT ‘NITIN’+1
SELECT ‘NITIN’+’1’
SELECT(SELECT ‘NITIN’)\
SELECT ‘1’+1
SELECT 1+’1’
12. Select case when null=null then ‘Amit’ else ‘Rahul’ end from dual;
What will be the output of the above query?
13. Explain character-manipulation functions? Explains its different types in SQL.
CONCAT
SUBSTR
LENGTH
INSTR
LPAD
RPAD
TRIM
REPLACE
14. Get the number of duplicate names and their frequency
Table – Employee
Name
Nitin
Amit
Gaurav
Nitin
Amit
Output
Nitin – 2
Amit – 2
Gaurav – 1
15. You always have a big data i.e. millions of rows in your tables, how would you partition it
for optimum performance?
16. Suppose in class, you have 3n boys and 2n girls with their names tabulated along with
their weight and gender. Write a SQL query to separate students alphabetically who are
over-weight (55kg for girls, 75kg for boys)
17. How can you create an empty table from an existing table? Write the steps and explain the
working.
18. What is the use of IFNULL and ISNULL in SQL?
19. You have got some data in the Table 1 and Table 2
Write a SQL query to create a Table 3 that contains the following columns- Id, First_Name,
Last_Name, Salary
20. What is CROSS JOIN UNNEST in Presto ?
21. What is LATERAL VIEW explode in Hive?
22. Suppose there are two tables, X and Y, X has just one column A and Y has B.
These are the two tables
Table X
Column A
1
1
1
Table Y
Column B
1
1
1
1
1
29 Ankush
Convert into
Name Nitin. Amit. Rishab. Ankush
Age. 25. 30. 27. 29
select 5
select ‘5’
select count (‘5’)
select count (5)
select count (*)
27. Find the number of people who are from Delhi and have arrived in Patna in the last 7 days
28. Write a SQL query to find all the patients who joined in the year 2022.
29. State the differences between views and tables.
30. Given a table dbo.users where the column user_id is a unique numeric identifier, how can
you efficiently select the first 100 odd user_id values from the table?
31. What will be the output of the below query, given an Employee table having 10 records?
BEGIN TRAN
TRUNCATE TABLE Employees
ROLLBACK
SELECT * FROM Employees
32. There is a table which contains two columns Student and Marks, you need to find all the
students, whose marks are greater than average marks i.e. list of above-average students.
33. How to Show the Max marks and min marks together from student table?
34. What do we need to check in Database Testing?