0% found this document useful (0 votes)
8 views

Mastering Data Analysis (SQL) - Day 10_11.PDF

The document outlines two data analysis tasks related to employee compensation and database usage. The first task involves identifying employees who earn more than their direct managers, while the second task focuses on analyzing SQL query usage by employees at IBM during Q3 2023. Solutions for both tasks are provided using SQL queries to extract the necessary data.

Uploaded by

rohitsul1112003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Mastering Data Analysis (SQL) - Day 10_11.PDF

The document outlines two data analysis tasks related to employee compensation and database usage. The first task involves identifying employees who earn more than their direct managers, while the second task focuses on analyzing SQL query usage by employees at IBM during Q3 2023. Solutions for both tasks are provided using SQL queries to extract the necessary data.

Uploaded by

rohitsul1112003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Mastering Data Analysis - Day 10 & 11

FAANG-Based Interview Question


Source - Data Lemur

Companies often perform salary analyses to ensure fair compensation practices.


One useful analysis is to check if there are any employees earning more than
their direct managers.

y
As a HR Analyst, you're asked to identify all employees who earn more than their
direct managers. The result should include the employee's ID and name.

ra
ta
an
m
Sa
a
rjy
su
Ai
SOLUTION
select DISTINCT
e.employee_id, e.name as employee_name
from employee as e
join employee as m
on m.employee_id = e.manager_id
where e.salary > m.salary

y
QUESTION 2

ra
IBM - INTERVIEW QUESTION

ta
IBM is analyzing how their employees are utilizing the Db2 database by tracking
the SQL queries executed by their employees. The objective is to generate data to
populate a histogram that shows the number of unique queries run by employees

an
during the third quarter of 2023 (July to September). Additionally, it should count
the number of employees who did not run any queries during this period.
m
Display the number of unique queries as histogram categories, along with the
count of employees who executed that number of unique queries.
Sa
a
rjy
su
Ai
y
ra
ta
an
m
Sa

SOLUTION::
a

WITH employee_queries AS (
rjy

SELECT
e.employee_id,
COALESCE(COUNT(DISTINCT q.query_id), 0) AS unique_queries
su

FROM employees AS e
LEFT JOIN queries AS q
ON e.employee_id = q.employee_id
AND q.query_starttime >= '2023-07-01T00:00:00Z'
Ai

AND q.query_starttime < '2023-10-01T00:00:00Z'


GROUP BY e.employee_id)
SELECT
unique_queries,
COUNT(employee_id) AS employee_count
FROM employee_queries
GROUP BY unique_queries
ORDER BY unique_queries;

You might also like