0% found this document useful (0 votes)
229 views14 pages

How Many Different Departments Are There in The Employee' Table. A)

Uploaded by

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

How Many Different Departments Are There in The Employee' Table. A)

Uploaded by

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

DATABASE MANAGEMENT SYSTEMS

ASSESSMENT 2

RISHIKA GOYAL

18BIT0270

EXERCISE 4:

1. How many different departments are there in the ‘employee’ table.

A)

SQL> SELECT COUNT(DISTINCT D_NO) FROM EMPLOYEE;

COUNT(DISTINCTD_NO)

-------------------

2. For each department display the minimum and maximum employee


salaries
A)

SQL> SELECT D_NO,MIN(SALARY),MAX(SALARY) FROM EMPLOYEE GROUP BY D_NO;


D_NO MIN(SALARY) MAX(SALARY)

---------- ----------- -----------

1 55000 55000
2 70000 70000
5 25000 40000
4 25000 43000

3 80000 80000

3. Print the average annual salary.

A)

SQL> SELECT 12*(SUM(SALARY)/COUNT(SALARY)) FROM EMPLOYEE;

12*(SUM(SALARY)/COUNT(SALARY))

------------------------------

517200

4. Count the number of employees over 30 age.

A)
SQL> SELECT COUNT(EMPSSNNO) FROM EMPLOYEE WHERE (EXTRACT(YEAR
FROM SYSDATE)-EXTRAC

T(YEAR FROM BIRTHDAY))>30;

COUNT(EMPSSNNO)

-------------

5. Print the Department name and average salary of each department.

A)
SQL> SELECT D_NO,AVG(SALARY) FROM EMPLOYEE GROUP BY D_NO;

D_NO AVG(SALARY)

---------- -----------

1 55000
2 70000

5 33250

4 31000
3 80000

6. Display the department name which contains more than 30


employees.
A)

SQL> SELECT D_NAME,COUNT(EMPSSNNO) FROM


EMPLOYEE JOIN DEPARTMENTS

ON EMPLOYEE.D_NO=DEPARTMENTS.D_NO GROUP BY

D_NAME HAVING(COUNT(EMPSSNNO)>30);

no rows selected

7. Calculate the average salary of employees by department and age


A)

SQL> SELECT AVG(SALARY) FROM EMPLOYEE ORDER BY D_NO,BIRTHDAY;

AVG(SALARY)

-----------

43100

8. Count separately the number of employees in the finance and


research department.
A)

SQL> SELECT COUNT(EMPSSNNO) FROM EMPLOYEE WHERE D_NO=4;

COUNT(EMPSSNNO)

---------------

SQL> SELECT COUNT(EMPSSNNO) FROM EMPLOYEE WHERE D_NO=5;

COUNT(EMPSSNNO)

---------------

4
EXERCISE 5
1. Find the employee who is getting highest salary in the dept research

SQL> select max(salary) from employee e, dept d where d.departmntnumber=e.depart


mentnumber and deptname='Research';

MAX(SALARY)
-----------
40000

2. Find the employees who earn the same salary as the minimum salary for each Dept

SQL> select ssnnumbernumber, firstname,midname,lastname from employee where salary=any


(select min(salary) from employee group by deptnumber);
SSNNUMBERNUMBER FIRSTNAME MI LASTNAME
--------- --------------- -- ---------------
554433221 Doug E Gilbert
453453453 Joyce A English
543216789 Joyce PAN
888665555 James E Bor
999887777 Alicia J Zelaya
987987987 Ahmad V Jabbar

3. Find the employee whose salary is greater than average salary of dept 2.

SQL> select firstname,midname,lastname from employee where salary > (select avg(
salary) from employee where deptnumber=2);

FIRSTNAME MI LASTNAME
--------------- -- ---------------
Doug E Gilbert

4. List out all the dept names with their individual employees strength

SQL> select deptname,count(*) from dept d, employee e where e.deptnu


mber=d.departmntnumber group by d.deptname;

DEPTNAME COUNT(*)
--------------- ----------
Research 4
Headquarter 1
Manufacture 1
Finance 3
Administration 1

5. Find out the dept name having highest employee strength

SQL> select deptname,count(*) from employee e join dept d on e.deptn


umber=d.departmntnumber group by d.deptname having count(*)=(select max(co
unt(*)) from employee group by deptnumber);

DEPTNAME COUNT(*)
--------------- ----------
Research 4
6. List out all the depts and average salary drawn by their employees

SQL> select deptname,avg(e.salary) from dept d, employee e where e.departm

entnumber=d.departmntnumber group by d.deptname;

DEPTNAME AVG(E.SALARY)

------------ -- -------------

Research 33250

Headquarter 80000

Manufacture 55000

Finance 31000

Administration 70000

7. Find maximum average salary for each dept

SQL> select max(salary) from employee where salary in (select avg(salary) from e
mployee group by deptnumber);

MAX(SALARY)
-----------
80000

8. Create a view to display the employee details who is working in IT dept.

SQL> create view v1 as select *from employee e,dept d where e.deptnumber=d


.departmntnumber and d.deptname='IT';

View created.

SQL> select *from v1


2;

no rows selected
9. Create a logical table to store employee details who is getting salary more than 10000.

SQL> create view v2 as select *from employee e where salary>10000;

View created.

SQL> select *from v2;

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------
Robert F Scott 943775543 21-JUN-42
2365 Newcastle Rd,Bellaire,TX M 58000 888665555
1

Doug E Gilbert 554433221 09-JUN-60


11 S 59 E,Salt Lake City,UTM 80000
3

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------

Joyce PAN 543216789 07-FEB-78


35 S 18 E,Salt Lake City,UT F 70000 NULL
5

Frankin T Wong 333445555 08-DEC-45


638 Voss,Houston,TX M 40000 554433221

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------
5

jENNIFER S Wallace 987654321 20-JUN-31


291 Berry,Bellair,TX F 43000 554433221
4

John B Smith 123456789 09-JAN-55

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------
731 Fondren,Houston,TX M 30000 333445555
5

Ramesh K Narayan 666884444 15-SEP-52


975 Fire Oak,Humble,TX M 38000 333445555
5

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------
Joyce A English 453453453 31-JUL-62
5631,Rice,Houton,TX F 25000 333445555
5

James E Bor 888665555 10-NOV-27


450 Stone,Houston,TX M 55000 543216789
1

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------
Alicia J Zelaya 999887777 19-JUL-58
3321 Castle,Spring,TX f 25000 987654321
4

Ahmad V Jabbar 987987987 29-MAR-59


980 Dallas,Houston,TX M 25000 987654321

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------
4

11 rows selected.

10. Create a table to store the employees details based on the dept no

SQL> create view v3 as select * from employee order by deptnumber;

View created.

SQL> select *from v3;

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------
James E Bor 888665555 10-NOV-27
450 Stone,Houston,TX M 55000 543216789
1

Robert F Scott 943775543 21-JUN-42


2365 Newcastle Rd,Bellaire,TX M 58000 888665555
1

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------

Doug E Gilbert 554433221 09-JUN-60


11 S 59 E,Salt Lake City,UTM 80000
3

Alicia J Zelaya 999887777 19-JUL-58


3321 Castle,Spring,TX f 25000 987654321

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------
4

jENNIFER S Wallace 987654321 20-JUN-31


291 Berry,Bellair,TX F 43000 554433221
4

Ahmad V Jabbar 987987987 29-MAR-59

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------
980 Dallas,Houston,TX M 25000 987654321
4

Joyce A English 453453453 31-JUL-62


5631,Rice,Houton,TX F 25000 333445555
5

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------
Ramesh K Narayan 666884444 15-SEP-52
975 Fire Oak,Humble,TX M 38000 333445555
5

Frankin T Wong 333445555 08-DEC-45


638 Voss,Houston,TX M 40000 554433221
5

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------

Joyce PAN 543216789 07-FEB-78


35 S 18 E,Salt Lake City,UT F 70000 NULL
5

John B Smith 123456789 09-JAN-55


731 Fondren,Houston,TX M 30000 333445555

FIRSTNAME MI LASTNAME SSNNUMBERNUMBER BIRTHDAY


--------------- -- --------------- --------- ---------
ADDRESS S SALARY SUPERVISO
-------------------------------------------------- - ---------- ---------
DEPTNUMBER
----------------
5

11 rows selected.

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