Mastering Data Analysis (SQL) - Day 10_11.PDF
Mastering Data Analysis (SQL) - Day 10_11.PDF
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