DAY 3 Task
DAY 3 Task
1. Write a SQL query to find the employee(s) earning the third highest salary from the
Employees table.
2. Write a SQL query to list all employees who have the same salary as another employee.
3. Create a stored procedure to give a 5% raise to all employees in the 'Sales'
department.
4. Write a query to find all departments with no assigned employees using a NOT EXISTS
clause.
5. Use a CTE (Common Table Expression) to find the average salary per department and
filter those with average above 75000.
6. Write a SQL query to pivot a table showing DepartmentName as rows and Budget
categories (Low, Medium, High) as columns with total employee counts.
7. Write a SQL query to list employees who joined in the last 6 months using a HireDate
field.
8. Write a query to count the number of projects each department is working on,
assuming a relationship via EmployeeID.
9. Create a view named "RecentHires" that includes all employees hired in the last year.
10. Write a SQL query to find departments with average salaries below the company-wide
average salary.
11. Use the RANK() window function to rank employees based on salary within each
department.
12. Write a SQL query to retrieve the names of employees whose department is in 'New
York' or 'Chicago'.
13. Generate a list of employee names along with the number of projects each is working
on, using JOIN and GROUP BY.
14. Find the department with the maximum number of employees using subqueries.
15. Write a SQL query that displays department name, total salary expense, and employee
count for departments with more than 3 employees.
16. Create a function that takes DepartmentID as input and returns the highest salary in
that department.
17. Write a SQL query that finds the difference between the highest and lowest salary for
each department.
18. Using nested subqueries, find employees who earn more than the maximum salary in
department 10.
19. Write a SQL query to delete employees who haven't worked on any project.
20. Find employees who are not assigned to any project using LEFT JOIN and IS NULL.
21. Write a query to return employees whose names contain a vowel followed
immediately by another vowel.
22. Create a query that categorizes employees into 'Junior', 'Mid-Level', and 'Senior' based
on Salary.
23. Write a query to fetch the top 3 employees with the highest salary from each
department.
24. Write a SQL query to return the length of the longest employee full name.
25. Write a SQL query to find employees whose FirstName and LastName start with the
same letter.
26. Use the CASE statement to create a bonus column: 10% of salary if >90000, else 5%.
27. Write a query that lists each department and the number of employees in that
department, even if zero.
28. Write a SQL query to find employees who work in more than one project using a
GROUP BY HAVING clause.
29. Create a trigger to prevent insertion into the Employees table if Salary is below 30000.
30. Write a query using a recursive CTE to build a hierarchy of departments assuming a
ParentDepartmentID structure.