0% found this document useful (0 votes)
10 views3 pages

SQL Vamsi

Uploaded by

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

SQL Vamsi

Uploaded by

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

1.Retrieve the number of employees hired each year.

select year(DateHired) as hyear ,count(EmployeeID) as noofemployee


from Employee
group by year(DateHired);

2.Find the average salary of employees in the Engineering department.


SELECT AVG(e.Salary) AS average_salary
FROM Employee e
JOIN Department d ON e.DepartmentID = d.DepartmentID
where d.DepartmentName='Engineering';

3.Retrieve the number of employees in each job title.


select JobTitle,count(*) as noofemployee
from Employee
group by JobTitle;

4.Find departments with more than 3 employees.


select DepartmentID
from Employee
group by DepartmentID
having count(DepartmentID)>3;

5.Retrieve the total number of projects handled by each project manager.


select count(p.ProjectID)as noofprojects
from Employee e join Project p
on e.ProjectID=p.ProjectID
group by p.ProjectID;

6.Find departments where the average salary is more than 80,000.


select DepartmentID
from employee
group by DepartmentID
having avg(Salary)>80000;

7.Count the number of employees without a project in each department.


select DepartmentID,count(EmployeeID) as noofemployees
from Employee
where ProjectID is null
group by DepartmentID;

8.Retrieve the total salary for all employees in the Marketing department.
select sum(Salary) as totalsal
from Employee e join Department d
on e.DepartmentID=d.DepartmentID
where DepartmentName='Marketing';

9.Find the earliest hire date for each department.


select DepartmentID ,min(DateHired)as earlyhiredate
from Employee
group by DepartmentID;

10.Retrieve the average salary for employees hired after 2020.


select avg(Salary) as avgsalary
from Employee
where DateHired>'2020';

11.Find the total number of employees with the same job title.
select JobTitle ,count(EmployeeID) as noofemployeeswithsametitle
from Employee
group by JobTitle;

12.List the number of projects each department is working on.


select count(ProjectId) as noofprojects
from Employee
group by DepartmentID;

13.Find the maximum salary in each project.


select max(Salary)as maxsalary
from Employee
group by ProjectID;

14.Retrieve departments where the total salary exceeds 300,000.


select DepartmentID
from Employee
group by DepartmentID
having sum(Salary)>300000;

15.Find the average number of years employees have worked in each department.
SELECT DepartmentID, AVG(DATEDIFF(YEAR, DateHired, GETDATE())) AS
average_years_worked
FROM Employee
GROUP BY DepartmentID;

16.Retrieve the names of employees along with their department names.


select e.FirstName,e.Lastname,d.DepartmentName
from Employee e join Department d
on e.DepartmentID=d.DepartmentID;

17.Find the projects that employees from the Sales department are working on.
select p.ProjectName
from Employee e join Department d
on e.DepartmentID=d.DepartmentID
join Project p on e.ProjectID=p.ProjectID
where d.DepartmentName='Sales';

18.Retrieve employees and their respective project names (if any).


select e.FirstName ,e.LastName,p.ProjectName
from Employee e join Project p
on e.ProjectID=p.ProjectID;

19.Find employees who work in the same department as "Priya Patel".

SELECT FirstName,LastName
FROM Employee
WHERE DepartmentID = (
SELECT DepartmentID
FROM Employee
WHERE FirstName = 'Priya' and LastName='Patel'
)
AND Firstname!='Priya' and LastName!= 'Patel';

20.Retrieve the names of managers for each department.

SELECT d.DepartmentName, e.FirstName AS managerfname,e.LastName as Managerlname


FROM Employee e
JOIN Department d ON e.DepartmentID = d.DepartmentID
WHERE e.DepartmentID = d.ManagerID;

21.Find employees who are working on "Project A".


select e.FirstName,e.LastName,p.ProjectName
from Employee e join Project p
on e.ProjectID=p.ProjectID
where ProjectName='Project A';

22.Retrieve employees and the names of their projects, if they are assigned one.
SELECT e.FirstName, p.ProjectName
FROM Employee e
LEFT JOIN Project p ON e.ProjectID = p.ProjectID;

23.Find employees who have been hired for longer than their department manager.
SELECT e.FirstName, e.DateHired, m.FirstName AS manager_name, m.DateHired AS
manager_hire_date
FROM Employee e
JOIN Employee m ON e.DepartmentID = m.DepartmentID
WHERE m.JobTitle In ('SalesManager','FinanceManager','HRManager')
AND e.DateHired < m.DateHired;

24.List all departments that have at least one employee working on "Project B".
SELECT DISTINCT d.DepartmentName
FROM Employee e
JOIN Project p ON e.ProjectID = p.ProjectID
JOIN Department d ON e.DepartmentID = d.DepartmentID
WHERE p.ProjectName = 'Project B';

25.Find employees who are working on projects managed by "Sandeep Garg".


SELECT e.FirstName,e.Lastname,p.ProjectName
FROM Employee e
JOIN Project p ON e.ProjectID = p.ProjectID
JOIN Employee m ON p.ProjectManagerID = m.EmployeeID
WHERE m.FirstName = 'Sandeep' and m.LastName='Garg';

26.Find employees whose project manager earns more than 100,000.


SELECT e.FirstName, e.Salary, p.ProjectName, m.FirstName AS manager_name, m.Salary
AS manager_salary
FROM Employee e
JOIN Project p ON e.EmployeeID = p.ProjectID
JOIN Employee m ON e.ProjectID = m.EmployeeID
WHERE m.Salary > 100000;

28.Find employees who do not work on any project.

SELECT e.FirstName
FROM Employee e
LEFT JOIN Project p ON e.ProjectID = p.ProjectID
WHERE p.ProjectID IS NULL;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy