18bit0166 Ayush Kanaujia
18bit0166 Ayush Kanaujia
SQL COMMAND:
select COUNT(distinct DepNo) from employee;
OUTPUT:
COUNT(DISTINCTDEPNO)
--------------------
5
2. For each department display the minimum and maximum employee salaries.
SQL COMMAND:
select min(salary),max(salary) from employee group by DepNo order by DepNo;
OUTPUT:
MIN(SALARY) MAX(SALARY)
----------- -----------
55000 55000
70000 70000
80000 80000
25000 43000
25000 40000
SQL COMMAND:
select avg(salary) from employee;
OUTPUT:
AVG(SALARY)
-----------
43100
SQL COMMAND:
SELECT count(ROUND((SYSDATE - TO_DATE(BDATE))/365.25, 2)) from employee where
ROUND((SYSDATE - TO_DATE(BDATE))/365.25, 2)>30;
OUTPUT:
COUNT(ROUND((SYSDATE-TO_DATE(BDATE))/365.25,2))
-----------------------------------------------
7
5. Print the Department name and average salary of each department.
SQL COMMAND:
select avg(employee.salary),Department.DName from employee join department on
employee.DepNo=Department.DepNo group by Department.DName;
OUTPUT:
AVG(EMPLOYEE.SALARY) DNAME
-------------------- --------------------
70000 Administration
33250 Research
80000 Headquarter
55000 Manufacture
31000 Finance
SQL COMMAND:
select count(*),Department.DName from employee join department on
employee.depno=department.depno group by department.dname having
count(dname)>30;
OUTPUT:
no rows selected
SQL COMMAND:
select count(*),Department.DName from employee join Department on
employee.DepNo=Department.DepNo where DNAME='Finance' or DNAME='Research'
group by Department.DNAME;
OUTPUT:
COUNT(*) DNAME
-------------- --------------------
4 Research
3 Finance
10. List out the employees who works in ‘manufacture’ department group by first name.
SQL COMMAND:
select employee.FName, Department.DName from employee join department on
employee.DepNo = Department.DepNo where Department.DName='Manufacture';
OUTPUT:
FNAME DNAME
---------- --------------------
James Manufacture
1. Find the employee who is getting highest salary in the department research.
SQL>
SELECT FNAME,LNAME FROM employee WHERE SALARY=(SELECT MAX(SALARY)
FROM employee LEFT JOIN department ON employee.DepNo=department.DepNo WHERE
department.DName='Research');
OUTPUT :-
FNAME LNAME
---------- ----------
Frankin Wong
2. Find the employees who earn the same salary as the minimum salary for each
Department.
6 rows selected.
3. Find the employee whose salary is greater than average salary of department 2.
OUTPUT:-
FNAME LNAME
---------- ----------
Doug Gilbert
Joyce PAN
4. List out all the department names with their individual employees strength.
OUTPUT:- Administration 1
Headquarter 1
Manufacture 1
Finance 3
Research 4
DNAME COUNT(EMPLOYEE.DEPNO)
------------------------- ---------------------
SQL>
SELECT DName FROM department WHERE DepNo=(SELECT DepNo FROM (SELECT
DepNo,count(DepNo) FROM employee GROUP BY DepNo ORDER BY count(DepNo)
DESC) WHERE ROWNUM=1);
OUTPUT:-
DNAME
-------------------------
Research
6. List out all the departments and average salary drawn by their employees.
OUTPUT:-
DNAME AVG(SALARY)
------------------------- -----------
Administration 70000
Research 33250
Headquarter 80000
Manufacture 55000
Finance 31000
OUTPUT:-
DNAME AVG
------------------------- ----------
Headquarter 80000
Administration 70000
Manufacture 55000
Research 33250
Finance 31000
8. Create a view to display the employee details who is working in IT department.
OUTPUT :- FNAME
LNAME
---------- ----------
Frankin Wong
John Smith
Ramesh Narayan
Joyce English
9. Create a logical table to store employee details who is getting salary more than 10000.
OUTPUT :-
FNAME LNAME SALARY DEPNO
---------- ---------- ---------- ----------
Doug Gilbert 80000 3
Joyce PAN 70000 2
Frankin Wong 40000 5
Jennifer Wallace 43000 4
John Smith 30000 5 Ramesh
Narayan 38000 5
Joyce English 25000 5
James Borg 55000 1
Alicia Zelaya 25000 4 Ahmad
Jabbar 25000 4
10. Create a table to store the employees details based on the department no.
1. Retrieve the names of all employees in department 5 who work more than 10 hours per
week on ProductX project.
OUTPUT :-
FNAME DEPNO
---------- ----------
Ramesh 5
Joyce 5
John 5
Frankin 5
2. List the names of all employees who have a dependent with the same first name as
themselves.
OUTPUT :- no
rows selected
3. Find the names of all the employees who are directly supervised by ‘Franklin Wong’.
OUTPUT :-
FNAME
----------
John
Ramesh
Joyce
OUTPUT :-
FNAME
---------- Jennifer
James
Ahmad
5. Find the names and addresses of all employees who work on at least one project located
in Houston but whose department has no location in Houston.
OUTPUT :- no
rows selected
OUTPUT :-
FNAME
----------
Doug
Ramesh
Alicia
Joyce
James
Joyce
Ahmad
7 rows selected.
7. List the employee’s names and the department names if they happen to manage a
department.
OUTPUT :-
FNAME DNAME
---------- -------------------------
Doug Headquarter
Joyce Administration
Frankin Research
Jennifer Finance
James Manufacture
8. For each project retrieve the project number, project name and the number of
employees who work on that project.
OUTPUT :-
9. For each project, list the project name and the total hours per week (by all employees)
spent on that project.
OUTPUT :-
PNAME SUM(HOURS)
--------------- ----------
Project B 29
Project C 10
Project J 57
Project E 30
Project A 72.5
Project I 35
6 rows selected.
10. Retrieve the names of the employees who have 2 or more dependents.
OUTPUT :- FNAME
LNAME
---------- ----------
Frankin Wong
John Smith