Professional Documents
Culture Documents
Dbms Lab Assignment - 5
Dbms Lab Assignment - 5
Create and insert data in – “emp” and “dept”(Check HR schema, table names may be different.)
QUERY:-
108 Nancy Greenberg NGREENBE 515.124.4569 17-AUG-02 FI_MGR 12008 - 101 100
FI_ACCOUN
109 Daniel Faviet DFAVIET 515.124.4169 16-AUG-02 9000 - 108 100
T
FI_ACCOUN
110 John Chen JCHEN 515.124.4269 28-SEP-05 8200 - 108 100
T
FI_ACCOUN
111 Ismael Sciarra ISCIARRA 515.124.4369 30-SEP-05 7700 - 108 100
T
FI_ACCOUN
112 Jose Manuel Urman JMURMAN 515.124.4469 07-MAR-06 7800 - 108 100
T
QUERY:-
CREATE TABLE DEPT AS SELECT * FROM HR.DEPARTMENTS;
INSERT INTO DEPT VALUES(6,'SUBH DEPT',77,360);
OUTPUT:-
DEPARTMENT_ID DEPARTMENT_NAME MANAGER_ID LOCATION_ID
6 SUBH DEPT 77 360
10 Administration 200 1700
20 Marketing 201 1800
30 Purchasing 114 1700
40 Human Resources 203 2400
50 Shipping 121 1500
60 IT 103 1400
70 Public Relations 204 2700
80 Sales 145 2500
90 Executive 100 1700
100 Finance 108 1700
110 Accounting 205 1700
120 Treasury - 1700
130 Corporate Tax - 1700
QUESTION 2:-
Display name of employees, department name and job name for each employee.
QUERY:-
select FIRST_NAME,LAST_NAME,DEPARTMENT_NAME,JOB_TITLE from HR.employees
e,HR.departments d,HR.jobs j where e.department_id= d.department_id and j.job_id=e.job_id;
OUTPUT:-
FIRST_NAME LAST_NAME DEPARTMENT_NAME JOB_TITLE
Jennifer Whalen Administration Administration Assistant
Michael Hartstein Marketing Marketing Manager
Pat Fay Marketing Marketing Representative
Shelli Baida Purchasing Purchasing Clerk
Alexander Khoo Purchasing Purchasing Clerk
Sigal Tobias Purchasing Purchasing Clerk
Guy Himuro Purchasing Purchasing Clerk
Karen Colmenares Purchasing Purchasing Clerk
Den Raphaely Purchasing Purchasing Manager
Susan Mavris Human Resources Human Resources Representative
Nandita Sarchand Shipping Shipping Clerk
QUESTION 3:-
Display the number of employees in each department in the order of their count of employees.(Note
– display the department with highest number of employees, followed by next highest, so on.)
QUERY:-
select department_id, count(*) from Hr.employees group by department_id order by count(*) desc;
OUTPUT:-
DEPARTMENT_I
COUNT(*)
D
50 45
80 34
100 6
30 6
60 5
90 3
20 2
110 2
10 1
- 1
40 1
70 1
QUESTION 4:-
Display the department name along with no of employees and average salary of the department.
QUERY:-
OUTPUT:-
QUESTION 5:-
For each department, find out no. of jobs the employees are assigned to.
QUERY:-
OUTPUT:-
DEPARTMENT_ID JOB_ID COUNT(*)
90 AD_VP 2
100 FI_MGR 1
80 SA_REP 29
- SA_REP 1
90 AD_PRES 1
20 MK_REP 1
110 AC_MGR 1
60 IT_PROG 5
30 PU_CLERK 5
80 SA_MAN 5
50 SH_CLERK 20
20 MK_MAN 1
30 PU_MAN 1
50 ST_CLERK 20
QUESTION 6:-
Find the maximum salary in each department , but only for those departments which have more
than one employee.(Display in order of department id.)
QUERY:-
OUTPUT:-
COUNT(*
DEPARTMENT_ID MAX(E.SALARY)
)
20 2 13000
30 6 11000
50 45 8200
60 5 9000
80 34 14000
90 3 24000
100 6 12008
110 2 12008
QUESTION 7:-
Group by the employees based on the first character of employee first name.Display the results in
alphabetic order(descending ) of first character.
QUERY:-
OUTPUT:-
TOTA
ALPHA
L
W 3
V 2
T 4
S 13
R 3
P 6
O 1
N 4
M 6
L 6
K 7
J 16
I 2
H 3
QUESTION 8:-
QUERY:-
OUTPUT:-
DEPARTMENT_I
COUNT(*)
D
50 40
30 5
QUESTION 9:-
-Apart from the above condition , make sure – only those departments are selected, which has
more than 3 ‘CLERK’ in it.
QUERY:-
OUTPUT:-
DEPARTMENT_ID COUNT(*)
10 1
20 2
30 6
40 1
50 45
60 5
70 1
80 34
90 3
100 6
110 2
- 1
QUESTION 10:-
Display the list of employees and their supervisor from “emp” table.
QUERY:-
OUTPUT:-
EMPLOYEE MANAGER
Gerald Cambrault Steven King
Lex De Haan Steven King
Alberto Errazuriz Steven King
Adam Fripp Steven King
Michael Hartstein Steven King
Payam Kaufling Steven King
Neena Kochhar Steven King
Kevin Mourgos Steven King
Karen Partners Steven King
Den Raphaely Steven King
QUESTION 11:-
Write query to find out any departments that are present in department table but does not have
employees.
QUERY:-
no data found