Practice Set 1
Practice Set 1
Retrieve the projects with their names and the total years of experience of all employees
working on them.
Q 2. Update the designation of employees to 'Senior Developer' if they have more than 5 years of
experience, 'Junior Developer' if they have more than 2 years of experience, and 'Intern' otherwise.
D. UPDATE Employee SET Emp_Desigination = CASE WHEN Emp_Expertiese > 5 THEN 'Junior
Developer' WHEN Emp_Expertiese > 2 THEN 'Intern' ELSE 'Senior Developer' END
Q 3. Find the doctors who have treated the most patients and show the total number of patients
they have treated.
Q 4. List the doctors who have treated patients with 'Heart Disease' and 'Hypertension,' and show
their names and the total number of such patients.
Q 5. Find the doctors who have treated patients with 'Asthma' and 'Allergies,' and show their names
and the total number of such patients.
Q 6. Retrieve the names of doctors who have not treated patients with 'Cancer' and have an
experience of more than 10 years.
Q 7. Calculate the average age of patients who are treated by doctors specializing in 'Pediatrics.'
A. SELECT AVG(YEAR(CURRENT_DATE) - YEAR(P.P_Birthdate)) AS Avg_Age FROM Patient P
INNER JOIN Treatment T ON P.P_id = T.P_id INNER JOIN Doctor D ON T.Dr_id = D.Dr_id
WHERE D.Dr_specialization = 'Oncology';
Q 8. Retrieve the names of employees and their corresponding designations, but if the designation is
'Manager,' display it as 'MGR,' 'Senior Developer' as 'Sr. Dev,' and 'Junior Developer' as 'Jr. Dev.'
B. SELECT Emp_Name, CASE Emp_Desigination WHEN 'Manager' THEN 'MGR' WHEN 'Senior
Developer' THEN 'Sr. Dev' WHEN 'Junior Developer' THEN 'Jr. Dev' ELSE Emp_Desigination
END FROM Employee
D. SELECT Emp_Name, CASE Emp_Desigination WHEN 'Manager' THEN 'MGR' WHEN 'Junior
Developer' THEN 'Jr. Dev' WHEN 'Senior Developer' THEN 'Sr. Dev' ELSE Emp_Desigination
END FROM Employee
Q 9. List the employees who have worked on projects in multiple project categories and classify them
as 'Versatile' employees.
A. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
GROUP BY Emp_ID HAVING COUNT(DISTINCT Project_id) > 1)
B. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
GROUP BY Emp_ID HAVING COUNT(Project_id) > 1)
C. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
GROUP BY Emp_ID HAVING COUNT(DISTINCT Project_id) = 1)
D. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
GROUP BY Emp_ID HAVING COUNT(Project_id) = 1)
Q 10. Find the doctors who have treated patients from 'Chicago' and have performed at least one 'CT
Scan' test.
A. SELECT D.Dr_Name FROM Doctor D INNER JOIN Treatment T ON D.Dr_id = T.Dr_id INNER
JOIN Patient P ON T.P_id = P.P_id INNER JOIN Test TS ON P.P_id = TS.P.id WHERE P.P_City =
'New York City' AND TS.Test_Name = 'MRI';
B. SELECT D.Dr_Name FROM Doctor D INNER JOIN Treatment T ON D.Dr_id = T.Dr_id INNER
JOIN Patient P ON T.P_id = P.P_id INNER JOIN Test TS ON P.P_id = TS.P_id WHERE P.P_City =
'Chicago' AND TS.Test_Name = 'CT Scan';
C. SELECT D.Dr_Name FROM Doctor D INNER JOIN Treatment T ON D.Dr_id = T.Dr_id INNER
JOIN Patient P ON T.P_id = P.P_id INNER JOIN Test TS ON P.P_id = TS.P_id WHERE P.P_City =
'New York City' AND TS.Test_Name = 'CT Scan';
D. SELECT D.Dr_Name FROM Doctor D INNER JOIN Treatment T ON D.Dr_id = T.Dr_id INNER
JOIN Patient P ON T.P_id = P.P_id INNER JOIN Test TS ON P.P_id = TS.P_id WHERE P.P_City =
'Chicago' AND TS.Test_Name = 'MRI';
Q 11. Update the salaries of employees by adding 10% for employees with more than 3 years of
experience, 15% for employees with more than 5 years, and 20% for employees with more than 10
years.
Q 12. List the projects and their categories, but if the project category is 'Development,' display it as
'DEV,' 'Research' as 'RSR,' and 'Management' as 'MGT.'
A. SELECT Project_Name, CASE Project_Categoery WHEN 'Development' THEN 'DEV' WHEN
'Management' THEN 'MGT' WHEN 'Research' THEN 'RSR' ELSE Project_Categoery END FROM
Project
Q 13. Retrieve the projects and their categories with the count of employees working on each
project.
Q 14. List the projects that have more than two employees assigned to them.
Q 15. List all employees who have worked on projects in the 'Development' category.
A. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id = (SELECT Project_ID FROM Project WHERE Project_Categoery <>
'Development'))
B. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id IN (SELECT Project_ID FROM Project WHERE Project_Categoery <>
'Development'))
C. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id = (SELECT Project_ID FROM Project WHERE Project_Categoery =
'Development'))
D. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id IN (SELECT Project_ID FROM Project WHERE Project_Categoery =
'Development'))
Q 16. Identify employees who have worked on projects with a budget exceeding $75,000, and if they
have less than 5 years of experience, grant them a bonus of 5% of the project's budget.
A. UPDATE Employee SET Emp_Bonus = Project_Budget * 0.05 FROM Employee INNER JOIN
Work ON Employee.Emp_ID = Work.Emp_ID INNER JOIN Project ON Work.Project_ID =
Project.Project_ID WHERE Project_Budget >= 75000 AND Emp_Expertiese >= 5
B. UPDATE Employee SET Emp_Bonus = Project_Budget * 0.05 FROM Employee INNER JOIN
Work ON Employee.Emp_ID = Work.Emp_ID INNER JOIN Project ON Work.Project_ID =
Project.Project_ID WHERE Project_Budget >= 75000 AND Emp_Expertiese < 5
C. UPDATE Employee SET Emp_Bonus = Project_Budget * 0.05 FROM Employee INNER JOIN
Work ON Employee.Emp_ID = Work.Emp_ID INNER JOIN Project ON Work.Project_ID =
Project.Project_ID WHERE Project_Budget > 75000 AND Emp_Expertiese >= 5
D. UPDATE Employee SET Emp_Bonus = Project_Budget * 0.05 FROM Employee INNER JOIN
Work ON Employee.Emp_ID = Work.Emp_ID INNER JOIN Project ON Work.Project_ID =
Project.Project_ID WHERE Project_Budget > 75000 AND Emp_Expertiese < 5
Q 17. Retrieve the names of patients who are allergic to 'Penicillin' and are treated by doctors
specializing in 'Allergy.'
A. SELECT P.P_Name FROM Patient P WHERE P.P_Allergies LIKE '%Penicillin%' AND P.P_id IN
(SELECT T.P_id FROM Treatment T INNER JOIN Doctor D ON T.Dr_id = D.Dr_id WHERE
D.Dr_specialization = 'Allergy')
B. SELECT P.P_Name FROM Patient P INNER JOIN Treatment T ON P.P_id = T.P_id INNER JOIN
Doctor D ON T.Dr_id = D.Dr_id WHERE P.P_Allergies LIKE '%Penicillin%' AND
D.Dr_specialization = 'Allergy'
C. SELECT P.P_Name FROM Patient P INNER JOIN Treatment T ON P.P_id = T.P_id INNER JOIN
Doctor D ON T.Dr_id = D.Dr_id WHERE P.P_Allergies LIKE '%Penicillin%' AND
D.Dr_specialization = 'Allergy'
D. SELECT P.P_Name FROM Patient P INNER JOIN Treatment T ON P.P_id = T.P_id INNER
JOIN Doctor D ON T.Dr_id = D.Dr_id WHERE P.P_Allergies LIKE '%Penicillin%' AND P.P_id IN
(SELECT T.P_id FROM Treatment T INNER JOIN Doctor D ON T.Dr_id = D.Dr_id WHERE
D.Dr_specialization = 'Allergy')
Q 18. Find the doctors who have treated patients from 'San Francisco' and have had at least one
patient from 'New York City.'
Q 20. Find the projects with the highest total budget. If multiple projects have the same highest
budget, choose the one with the most employees.
Q 21. Retrieve the names of doctors who have treated the same patient more than once, and show
the patient's name and the number of treatments.
Q 22. Calculate the average project duration in days, but if a project has a duration of more than 90
days, categorize it as 'Long-Term,' between 30 and 90 days as 'Medium-Term,' and less than 30 days
as 'Short-Term.'
Q 23. Update the designation of employees with more than 10 years of experience to 'Senior
Developer.'
Q 24. Find the projects that have at least one employee with expertise in 'Java.'
Q 25. Identify employees who have worked on projects with a budget exceeding $100,000 and have
more than 5 years of experience. Update their designation to 'Project Lead.'
Q 27. Calculate the average salary for employees in each department, but if the average salary is
below $50,000, categorize the department as 'Low Pay,' between $50,000 and $75,000 as 'Average
Pay,' and above $75,000 as 'High Pay.'
C. SELECT Department, CASE WHEN AVG(Emp_Salary) < 50000 THEN 'High Pay' WHEN
AVG(Emp_Salary) >= 50000 AND AVG(Emp_Salary) <= 75000 THEN 'Low Pay' ELSE 'Average
Pay' END FROM Employee GROUP BY Department
D. SELECT Department, CASE WHEN AVG(Emp_Salary) < 50000 THEN 'Low Pay' WHEN
AVG(Emp_Salary) >= 50000 AND AVG(Emp_Salary) <= 75000 THEN 'High Pay' ELSE 'Average
Pay' END FROM Employee GROUP BY Department
Q 28. Calculate the total bonus for employees who have more than 3 years of experience. If the
bonus is above $2,000, categorize it as 'High Bonus,' between $1,000 and $2,000 as 'Medium Bonus,'
and below $1,000 as 'Low Bonus.'
C. SELECT Emp_Name, SUM(Emp_Bonus), CASE WHEN SUM(Emp_Bonus) > 1000 THEN 'Low
Bonus' WHEN SUM(Emp_Bonus) >= 2000 THEN 'Medium Bonus' ELSE 'High Bonus' END
FROM Employee WHERE Emp_Expertiese > 3 GROUP BY Emp_Name
Q 29. Identify the patients who have been treated by doctors from the same city and specialization
as the patient, and show the names of the doctors.
Q 30. List the employees who have not been assigned to any projects yet.
A. SELECT Emp_Name FROM Employee WHERE Emp_ID IS NULL
B. SELECT Emp_Name FROM Employee WHERE Emp_ID NOT IN (SELECT Emp_ID FROM
Work)
C. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work)
Q 31. List the doctors who have treated patients from 'New York City' and have performed more than
3 different tests.
Q 32. Retrieve the names of patients who have not had any tests and are treated by doctors with less
than 5 years of experience.
A. SELECT P.P_Name FROM Patient P WHERE P.P_id NOT IN (SELECT T.P_id FROM Test T)
AND P.P_id NOT IN (SELECT D.P_id FROM Doctor D WHERE D.Dr_Experience < 5);
B. SELECT P.P_Name FROM Patient P WHERE P.P_id IN (SELECT T.P_id FROM Test T) AND
P.P_id NOT IN (SELECT D.P_id FROM Doctor D WHERE D.Dr_Experience < 5);
C. SELECT P.P_Name FROM Patient P WHERE P.P_id IN (SELECT T.P_id FROM Test T) AND
P.P_id IN (SELECT D.P_id FROM Doctor D WHERE D.Dr_Experience < 5);
D. SELECT P.P_Name FROM Patient P WHERE P.P_id NOT IN (SELECT T.P_id FROM Test T)
AND P.P_id IN (SELECT D.P_id FROM Doctor D WHERE D.Dr_Experience < 5);
Q 33. Find the employees who have the same designation as their project category.
Q 34. Find the total number of patients admitted by each doctor, but only if the doctor has treated
more than 10 patients.
Q 35. Find the patients who have been treated by doctors from the 'Bay Area' and have had both 'X-
ray' and 'MRI' tests.
A. SELECT P.P_Name, P.P_id FROM Patient P INNER JOIN Treatment T ON P.P_id = T.P_id
INNER JOIN Doctor D ON T.Dr_id = D.Dr_id INNER JOIN Test TS ON P.P_id = TS.P_id WHERE
P.P_City = 'Bay Area' AND TS.Test_Name IN ('X-ray', 'MRI') GROUP BY P.P_id, P.P_Name
HAVING COUNT(DISTINCT TS.Test_Name) = 2;
B. SELECT P.P_Name, P.P_id FROM Patient P INNER JOIN Treatment T ON P.P_id = T.P_id
INNER JOIN Doctor D ON T.Dr_id = D.Dr_id INNER JOIN Test TS ON P.P_id = TS.P_id WHERE
P.P_City = 'Bay Area' AND TS.Test_Name IN ('X-ray', 'CT Scan') GROUP BY P.P_id, P.P_Name
HAVING COUNT(DISTINCT TS.Test_Name) = 2;
C. SELECT P.P_Name, P.P_id FROM Patient P INNER JOIN Treatment T ON P.P_id = T.P_id
INNER JOIN Doctor D ON T.Dr_id = D.Dr_id INNER JOIN Test TS ON P.P_id = TS.P_id WHERE
P.P_City = 'New York City' AND TS.Test_Name IN ('X-ray', 'MRI') GROUP BY P.P_id, P.P_Name
HAVING COUNT(DISTINCT TS.Test_Name) = 2;
D. SELECT P.P_Name, P.P_id FROM Patient P INNER JOIN Treatment T ON P.P_id = T.P_id
INNER JOIN Doctor D ON T.Dr_id = D.Dr_id INNER JOIN Test TS ON P.P_id = TS.P_id WHERE
P.P_City = 'Bay Area' AND TS.Test_Name IN ('X-ray', 'MRI') GROUP BY P.P_id, P.P_Name
HAVING COUNT(DISTINCT TS.Test_Name) = 1;
Q 36. Calculate the total cost of treatment for patients who have been admitted more than once and
are treated by doctors specializing in 'Surgery.'
Q 38. Retrieve the projects with the highest number of employees working on them.
Q 39. List the employees who are working on projects with a specific technology, e.g., 'SQL Server.'
A. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Technology = 'SQL Server')
B. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Technology LIKE '%SQL Server%')
C. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Technology IN ('SQL Server', 'SQL'))
D. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Technology = 'MySQL')
Q 40. Retrieve the employee names who are working on projects that are not in the 'Research'
category.
A. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id IN (SELECT Project_ID FROM Project WHERE Project_Categoery =
'Development'))
B. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id IN (SELECT Project_ID FROM Project WHERE Project_Categoery <>
'Research'))
C. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id IN (SELECT Project_ID FROM Project WHERE Project_Categoery =
'Development'))
D. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id NOT IN (SELECT Project_ID FROM Project WHERE Project_Categoery =
'Research'))
Q 41. List the doctors who have not treated patients from 'Los Angeles' and have performed more
than 5 tests in total.
A. SELECT D.Dr_Name FROM Doctor D LEFT JOIN Treatment T ON D.Dr_id = T.Dr_id LEFT
JOIN Patient P ON T.P_id = P.P_id LEFT JOIN Test TS ON P.P_id = TS.P_id WHERE P.P_City = 'Los
Angeles' GROUP BY D.Dr_id, D.Dr_Name HAVING COUNT(DISTINCT TS.Test_id) <= 5;
B. SELECT D.Dr_Name FROM Doctor D LEFT JOIN Treatment T ON D.Dr_id = T.Dr_id LEFT
JOIN Patient P ON T.P_id = P.P_id LEFT JOIN Test TS ON P.P_id = TS.P_id WHERE P.P_City <>
'Los Angeles' OR P.P_id IS NULL GROUP BY D.Dr_id, D.Dr_Name HAVING COUNT(DISTINCT
TS.Test_id) > 5;
C. SELECT D.Dr_Name FROM Doctor D LEFT JOIN Treatment T ON D.Dr_id = T.Dr_id LEFT
JOIN Patient P ON T.P_id = P.P_id LEFT JOIN Test TS ON P.P_id = TS.P_id WHERE P.P_City = 'Los
Angeles' GROUP BY D.Dr_id, D.Dr_Name HAVING COUNT(DISTINCT TS.Test_id) > 5;
D. SELECT D.Dr_Name FROM Doctor D LEFT JOIN Treatment T ON D.Dr_id = T.Dr_id LEFT
JOIN Patient P ON T.P_id = P.P_id LEFT JOIN Test TS ON P.P_id = TS.P_id WHERE P.P_City <>
'Los Angeles' OR P.P_id IS NULL GROUP BY D.Dr_id, D.Dr_Name HAVING COUNT(DISTINCT
TS.Test_id) <= 5;
Q 42. Find the projects where the total budget exceeds $100,000, and categorize them as 'High
Budget.' If the budget is between $50,000 and $100,000, categorize them as 'Medium Budget,' and
below $50,000 as 'Low Budget.'
A. SELECT Project_Name, CASE WHEN Project_Budget >= 50000 AND Project_Budget <=
100000 THEN 'Low Budget' WHEN Project_Budget > 100000 THEN 'High Budget' ELSE
'Medium Budget' END FROM Project
B. SELECT Project_Name, CASE WHEN Project_Budget >= 50000 AND Project_Budget <=
100000 THEN 'High Budget' WHEN Project_Budget > 100000 THEN 'Medium Budget' ELSE
'Low Budget' END FROM Project
C. SELECT Project_Name, CASE WHEN Project_Budget > 100000 THEN 'High Budget' WHEN
Project_Budget >= 50000 AND Project_Budget <= 100000 THEN 'Medium Budget' ELSE 'Low
Budget' END FROM Project
D. SELECT Project_Name, CASE WHEN Project_Budget >= 50000 AND Project_Budget <=
100000 THEN 'Medium Budget' WHEN Project_Budget > 100000 THEN 'High Budget' ELSE
'Low Budget' END FROM Project
Q 43. List the patients who have had multiple treatments and show the names of their treating
doctors for each treatment.
A. SELECT P.P_Name, T.P_id, D.Dr_Name, T.Dr_id FROM Patient P INNER JOIN Treatment T
ON P.P_id = T.P_id INNER JOIN Doctor D ON T.Dr_id = D.Dr_id WHERE T.P_id IN (SELECT T.P_id
FROM Treatment T GROUP BY T.P_id HAVING COUNT(Treatment_id) > 1);
B. SELECT P.P_Name, T.P_id, D.Dr_Name, T.Dr_id FROM Patient P INNER JOIN Treatment T
ON P.P_id = T.P_id INNER JOIN Doctor D ON T.Dr_id = D.Dr_id WHERE T.P_id IN (SELECT T.P_id
FROM Treatment T GROUP BY T.P_id HAVING COUNT(Treatment_id) >= 2);
C. SELECT P.P_Name, T.P_id, D.Dr_Name, T.Dr_id FROM Patient P INNER JOIN Treatment T
ON P.P_id = T.P_id INNER JOIN Doctor D ON T.Dr_id = D.Dr_id WHERE T.P_id IN (SELECT T.P_id
FROM Treatment T GROUP BY T.P_id HAVING COUNT(Treatment_id) <= 1);
D. SELECT P.P_Name, T.P_id, D.Dr_Name, T.Dr_id FROM Patient P INNER JOIN Treatment T
ON P.P_id = T.P_id INNER JOIN Doctor D ON T.Dr_id = D.Dr_id WHERE T.P_id IN (SELECT T.P_id
FROM Treatment T GROUP BY T.P_id HAVING COUNT(Treatment_id) < 2);
Q 44. Retrieve a list of employees with their project details (Emp_Name, Project_Name).
D. SELECT Emp_Name, Project_Name FROM Employee CROSS JOIN Work CROSS JOIN
Project
Q 45. Retrieve the names of employees who have more than 5 years of experience.
Q 46. Calculate the total salary of each employee, including a bonus of $500 for employees with the
designation 'Manager' and $200 for employees with the designation 'Senior Developer.'
A. SELECT Project_Name, CASE WHEN Project_Start_Date < '2022-01-01' THEN 'Old Project'
ELSE 'Recent Project' END FROM Project
C. SELECT Project_Name, CASE WHEN Project_Start_Date > '2022-01-01' THEN 'Old Project'
ELSE 'Recent Project' END FROM Project
Q 48. List the employees who are assigned to projects with the word 'Database' in their project
name.
A. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id IN (SELECT Project_ID FROM Project WHERE Project_Name LIKE
'%Database%'))
B. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id = (SELECT Project_ID FROM Project WHERE Project_Name LIKE
'Database'))
C. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id = (SELECT Project_ID FROM Project WHERE Project_Name = 'Database'))
D. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id = (SELECT Project_ID FROM Project WHERE Project_Name IN ('Database',
'Data Storage')))
Q 49. Calculate the average treatment cost for patients who have been admitted more than once and
are treated by doctors specializing in 'Cardiology.'
Q 50. Retrieve the names of doctors who have treated patients from the 'Bay Area' and have
performed at least one 'MRI' test.
Q 51. Calculate the average treatment duration for patients admitted by doctors specializing in
'Oncology' and who have had more than one treatment.
Q 52. Identify the patients with the highest number of admissions, and show the details of their
treating doctors.
A. SELECT P.P_Name, P.P_id, D.Dr_Name, D.Dr_id FROM Patient P INNER JOIN (SELECT
T.P_id, T.Dr_id, COUNT(Treatment_id) AS Admissions FROM Treatment T GROUP BY T.P_id,
T.Dr_id HAVING Admissions = (SELECT MAX(Admissions) FROM (SELECT P_id, Dr_id,
COUNT(Treatment_id) AS Admissions FROM Treatment T GROUP BY P_id, Dr_id) AS
Subquery)) AS Subquery ON P.P_id = Subquery.P_id INNER JOIN Doctor D ON Subquery.Dr_id
= D.Dr_id;
B. SELECT P.P_Name, P.P_id, D.Dr_Name, D.Dr_id FROM Patient P INNER JOIN (SELECT
T.P_id, T.Dr_id, COUNT(Treatment_id) AS Admissions FROM Treatment T GROUP BY T.P_id,
T.Dr_id HAVING Admissions = (SELECT MIN(Admissions) FROM (SELECT P_id, Dr_id,
COUNT(Treatment_id) AS Admissions FROM Treatment T GROUP BY P_id, Dr_id) AS
Subquery)) AS Subquery ON P.P_id = Subquery.P_id INNER JOIN Doctor D ON Subquery.Dr_id
= D.Dr_id;
C. SELECT P.P_Name, P.P_id, D.Dr_Name, D.Dr_id FROM Patient P INNER JOIN (SELECT
T.P_id, T.Dr_id, COUNT(Treatment_id) AS Admissions FROM Treatment T GROUP BY T.P_id,
T.Dr_id HAVING Admissions = (SELECT MAX(Admissions) FROM (SELECT P_id, Dr_id,
COUNT(Treatment_id) AS Admissions FROM Treatment T GROUP BY P_id, Dr_id) AS
Subquery)) AS Subquery ON P.P_id = Subquery.P_id INNER JOIN Doctor D ON Subquery.Dr_id
= D.Dr_id;
D. SELECT P.P_Name, P.P_id, D.Dr_Name, D.Dr_id FROM Patient P INNER JOIN (SELECT
T.P_id, T.Dr_id, COUNT(Treatment_id) AS Admissions FROM Treatment T GROUP BY T.P_id,
T.Dr_id HAVING Admissions = (SELECT AVG(Admissions) FROM (SELECT P_id, Dr_id,
COUNT(Treatment_id) AS Admissions FROM Treatment T GROUP BY P_id, Dr_id) AS
Subquery)) AS Subquery ON P.P_id = Subquery.P_id INNER JOIN Doctor D ON Subquery.Dr_id
= D.Dr_id;
Q 53. Calculate the average number of tests performed on patients who are allergic to 'Peanuts' and
are treated by doctors with a specialization of 'Allergy.'
Q 55. Calculate the average project cost, but if a project cost is over $50,000, categorize it as
'Expensive,' between $20,000 and $50,000 as 'Moderate,' and below $20,000 as 'Inexpensive.'
Q 56. Find the projects and their categories along with the employee assigned to each project.
Q 57. Retrieve the names of patients who have had more than 5 different tests and are treated by
doctors with more than 15 years of experience.
Q 58. List the employees who have worked on projects with 'Database' in the project name and are
designated as 'Developer.'
A. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id IN (SELECT Project_ID FROM Project WHERE Project_Name LIKE
'%Database%')) AND Emp_Desigination = 'Developer'
B. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id IN (SELECT Project_ID FROM Project WHERE Project_Name LIKE
'%Database%') AND Emp_Desigination = 'Developer')
C. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id IN (SELECT Project_ID FROM Project WHERE Project_Name = 'Database')
AND Emp_Desigination = 'Developer')
D. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
WHERE Project_id IN (SELECT Project_ID FROM Project WHERE Project_Name = 'Database'))
AND Emp_Desigination = 'Developer'
Q 59. List all employees who have worked on projects with a total duration of more than 180 days
and have designations of 'Manager' or 'Senior Developer.'
A. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
GROUP BY Emp_ID HAVING SUM(Project_Duration) > 180) AND (Emp_Desigination = 'Junior
Developer' OR Emp_Desigination = 'Manager')
B. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
GROUP BY Emp_ID HAVING SUM(Project_Duration) > 180) AND (Emp_Desigination = 'Senior
Developer' OR Emp_Desigination = 'Junior Developer')
C. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
GROUP BY Emp_ID HAVING SUM(Project_Duration) > 180) AND (Emp_Desigination = 'Senior
Developer' OR Emp_Desigination = 'Manager')
D. SELECT Emp_Name FROM Employee WHERE Emp_ID IN (SELECT Emp_ID FROM Work
GROUP BY Emp_ID HAVING SUM(Project_Duration) > 180) AND (Emp_Desigination =
'Manager' OR Emp_Desigination = 'Junior Developer')
Q 60. Find the employees who have the same expertise as another employee with Emp_ID 101.
Q 61. Calculate the average years of experience for all employees and categorize them as 'Junior,'
'Intermediate,' or 'Senior.'
Q 62. List the patients who have had more tests than their age and show the total number of tests
they've undergone.
Q 63. Find the doctors who have treated patients with 'Hypertension' and have performed more 'CT
Scan' tests than 'X-ray' tests.
A. SELECT D.Dr_Name FROM Doctor D INNER JOIN Treatment T ON D.Dr_id = T.Dr_id INNER
JOIN Patient P ON T.P_id = P.P_id INNER JOIN Test TS ON P.P_id = TS.P_id WHERE P.P_Disease
= 'Hypertension' AND TS.Test_Name = 'CT Scan' GROUP BY D.Dr_id, D.Dr_Name HAVING
COUNT(TS.Test_id) > (SELECT COUNT(TS.Test_id) FROM Test TS WHERE TS.Test_Name = 'X-
ray');
B. SELECT D.Dr_Name FROM Doctor D INNER JOIN Treatment T ON D.Dr_id = T.Dr_id INNER
JOIN Patient P ON T.P_id = P.P_id INNER JOIN Test TS ON P.P_id = TS.P_id WHERE P.P_Disease
= 'Asthma' AND TS.Test_Name = 'CT Scan' GROUP BY D.Dr_id, D.Dr_Name HAVING
COUNT(TS.Test_id) > (SELECT COUNT(TS.Test_id) FROM Test TS WHERE TS.Test_Name = 'X-
ray');
C. SELECT D.Dr_Name FROM Doctor D INNER JOIN Treatment T ON D.Dr_id = T.Dr_id INNER
JOIN Patient P ON T.P_id = P.P_id INNER JOIN Test TS ON P.P_id = TS.P_id WHERE P.P_Disease
= 'Hypertension' AND TS.Test_Name = 'X-ray' GROUP BY D.Dr_id, D.Dr_Name HAVING
COUNT(TS.Test_id) > (SELECT COUNT(TS.Test_id) FROM Test TS WHERE TS.Test_Name = 'CT
Scan');
D. SELECT D.Dr_Name FROM Doctor D INNER JOIN Treatment T ON D.Dr_id = T.Dr_id INNER
JOIN Patient P ON T.P_id = P.P_id INNER JOIN Test TS ON P.P_id = TS.P_id WHERE P.P_Disease
= 'Asthma' AND TS.Test_Name = 'X-ray' GROUP BY D.Dr_id, D.Dr_Name HAVING
COUNT(TS.Test_id) > (SELECT COUNT(TS.Test_id) FROM Test TS WHERE TS.Test_Name = 'CT
Scan');
Q 64. Calculate the total treatment cost for patients who have been admitted on or after '2023-01-
01' and have 'Diabetes.'
A. SELECT T.P_id, SUM(Treatment_Cost) AS Total_Cost FROM Treatment T INNER JOIN
Patient P ON T.P_id = P.P_id WHERE P.P_Disease = 'Cancer' AND T.Admit_Date < '2023-01-01'
GROUP BY T.P_id;
Q 65. Identify employees who have worked on more than 3 projects and have designations of either
'Senior Developer' or 'Manager,' and grant them a performance bonus of $1,000.
A. UPDATE Employee SET Emp_Bonus = 1000 WHERE Emp_ID IN (SELECT Emp_ID FROM
Work GROUP BY Emp_ID HAVING COUNT(Project_ID) > 3) AND (Emp_Desigination = 'Junior
Developer' OR Emp_Desigination = 'Manager')
B. UPDATE Employee SET Emp_Bonus = 1000 WHERE Emp_ID IN (SELECT Emp_ID FROM
Work GROUP BY Emp_ID HAVING COUNT(Project_ID) > 3) AND (Emp_Desigination = 'Senior
Developer' OR Emp_Desigination = 'Junior Developer')
C. UPDATE Employee SET Emp_Bonus = 1000 WHERE Emp_ID IN (SELECT Emp_ID FROM
Work GROUP BY Emp_ID HAVING COUNT(Project_ID) = 3) AND (Emp_Desigination = 'Senior
Developer' OR Emp_Desigination = 'Manager')
D. UPDATE Employee SET Emp_Bonus = 1000 WHERE Emp_ID IN (SELECT Emp_ID FROM
Work GROUP BY Emp_ID HAVING COUNT(Project_ID) > 3) AND (Emp_Desigination = 'Senior
Developer' OR Emp_Desigination = 'Manager')
Q 66. List the patients who have been treated by doctors from 'San Francisco' and have had both
'Blood Test' and 'X-ray' tests.
A. SELECT P.P_Name FROM Patient P WHERE P.P_City = 'San Francisco' AND P.P_id IN
(SELECT P_id FROM Test WHERE Test_Name = 'Blood Test') AND P.P_id IN (SELECT P_id FROM
Test WHERE Test_Name = 'X-ray');
B. SELECT P.P_Name FROM Patient P WHERE P.P_City = 'San Francisco' AND P.P_id NOT IN
(SELECT P_id FROM Test WHERE Test_Name = 'Blood Test') AND P.P_id NOT IN (SELECT P_id
FROM Test WHERE Test_Name = 'X-ray');
C. SELECT P.P_Name FROM Patient P WHERE P.P_City = 'New York City' AND P.P_id IN
(SELECT P_id FROM Test WHERE Test_Name = 'Blood Test') AND P.P_id IN (SELECT P_id FROM
Test WHERE Test_Name = 'X-ray');
D. SELECT P.P_Name FROM Patient P WHERE P.P_City = 'New York City' AND P.P_id NOT IN
(SELECT P_id FROM Test WHERE Test_Name = 'Blood Test') AND P.P_id NOT IN (SELECT P_id
FROM Test WHERE Test_Name = 'X-ray');
Q 67. List the projects and their categories, but if the project category is 'Management,' display it as
'MGT,' 'Development' as 'DEV,' and 'Research' as 'RSR.'
Q 68. Calculate the average number of tests performed on patients from 'Los Angeles' who have had
treatments by doctors with more than 10 years of experience.
Q 69. Identify employees who have the highest salary in their respective departments and update
their designations to 'Department Head.'
Q 70. Update the designation of employees to 'Manager' if they have more than 5 years of
experience, 'Senior Developer' if they have more than 10 years of experience, and 'Junior Developer'
otherwise.