SQL Assignment 2
SQL Assignment 2
Assignment # 2
2. Display the Empno and number of assign Project Tasks if the Employee assigns more than 1
project Tasks in EmpProjectTasks table.
3. Display the number of Employee in each department from the table Employees &
Departments tables.
7. Display department number, names and salaries of employees who are earning max salary in
their departments.
9. Display department number, names and salaries of employees who are earning max salary in
their departments
10. Display client name whose project’s ‘Coding’ task is ‘In Progress’.
11. Display names of employees doing ‘System Analysis’ along with project name
13. Display all employee numbers present in both Employees and EmpProjectTasks table.
MS SQL Server
Assignment # 2
Q2.Display the Empno and number of assign Project Tasks if the Employee assigns more than 1
project Tasks in EmpProjectTasks table.
Q3.Display the number of Employee in each department from the table Employees &
Departments tables.
Ans - SELECT DNAME, count(*) [No of employees] from acroschema_17.EMPLOYEES a inner join
acroschema_17.DEPARTMENTS b on
a.DEPTNO = b.DEPTNO group by DNAME
Q4.Display department wise count and sum of salary of employees.
Q7..Display department number, names and salaries of employees who are earning max salary in
their departments.
Q9.Display department number, names and salaries of employees who are earning max salary in
their departments.
ANS - SELECT a.DEPTNO ,ENAME, max(SALARY) [MAX SALARY] from acroschema_17.EMPLOYEES a
left join acroschema_17.DEPARTMENTS
b on a.DEPTNO = b.DEPTNO group by a.DEPTNO,ENAME order by [MAX SALARY] desc
Q10.Display client name whose project’s ‘Coding’ task is ‘In Progress’.
ANS - SELECT CNAME from acroschema_17.CLIENTS t1 inner join
acroschema_17.PROJECTS t2 on t1.CLIENT_ID = t2.CLIENT_ID
inner join acroschema_17.EMPPROJECTTASKS t3 on t2.PROJECT_ID = t3.PROJECT_ID
and t3.TASK = 'Coding' and t3.STATUS = 'In Progress'
Q11.Display names of employees doing ‘System Analysis’ along with project name
ANS - SELECT ENAME, DESCR from acroschema_17.EMPLOYEES t1 inner join
acroschema_17.EMPPROJECTTASKS
t2 on t1.EMPNO = t2.EMPNO inner join acroschema_17.PROJECTS t3 on t3.PROJECT_ID = t2.PROJECT_ID
where TASK = 'System Analysis'
t1.EMPNO = t2.EMPNO