Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

QUESTION 1:-

Create and insert data in – “emp” and “dept”(Check HR schema, table names may be different.)

QUERY:-

CREATE TABLE EMP AS SELECT * FROM HR.EMPLOYEES;


INSERT INTO EMP VALUES(99, 'SUBHAM','MUDI','subham@gmail.com',9831267354,'28-JUN-
22','IT_PROG',250000,.1,100,90);
SELECT * FROM EMP ORDER BY EMPLOYEE_ID;
OUTPUT:-
EMPLOYEE_I LAST_NAM PHONE_NUMBE MANAGER DEPARTMENT
FIRST_NAME EMAIL HIRE_DATE JOB_ID SALARY COMMISSION_PCT
D E R _ID _ID

99 SUBHAM MUDI subham@gmail.com 9831267354 28-JUN-22 IT_PROG 250000 .1 100 90

100 Steven King SKING 515.123.4567 17-JUN-03 AD_PRES 24000 - - 90

101 Neena Kochhar NKOCHHAR 515.123.4568 21-SEP-05 AD_VP 17000 - 100 90

102 Lex De Haan LDEHAAN 515.123.4569 13-JAN-01 AD_VP 17000 - 100 90

103 Alexander Hunold AHUNOLD 590.423.4567 03-JAN-06 IT_PROG 9000 - 102 60

104 Bruce Ernst BERNST 590.423.4568 21-MAY-07 IT_PROG 6000 - 103 60

105 David Austin DAUSTIN 590.423.4569 25-JUN-05 IT_PROG 4800 - 103 60

106 Valli Pataballa VPATABAL 590.423.4560 05-FEB-06 IT_PROG 4800 - 103 60

107 Diana Lorentz DLORENTZ 590.423.5567 07-FEB-07 IT_PROG 4200 - 103 60

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:-

select d.department_name, count(*),round(avg(e.salary),2) as avgsalary from HR.employees e inner


join HR.departments d on e.department_id=d.department_id group by d.department_name order
by count(*) desc;

OUTPUT:-
QUESTION 5:-

For each department, find out no. of jobs the employees are assigned to.

QUERY:-

select department_id,job_id,count(*) from HR.employees group by department_id ,job_id;

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:-

select department_id,count(*),max(e.salary) from HR.employees e group by department_id having


count(*)>1 order by department_id;

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:-

select substr(first_name,1,1) as alpha, count(*)as total from HR.employees group by


substr(first_name,1,1) order by substr(first_name,1,1) desc;

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:-

Display department id wise count of employees.

QUERY:-

select e.department_id,count(*) from HR.employees e inner join HR.jobs j on j.job_id=e.job_id


where j.job_title like '%Clerk%' group by e.department_id having count(*) > 3;

OUTPUT:-
DEPARTMENT_I
COUNT(*)
D
50 40
30 5
QUESTION 9:-

-who are ‘CLERK’

-Apart from the above condition , make sure – only those departments are selected, which has
more than 3 ‘CLERK’ in it.

QUERY:-

select department_id, count(*) from HR.employees group by department_id order by


department_id;

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:-

select e1.first_name||' '||e1.last_name as Employee, e2.first_name||' '||e2.last_name as Manager


from HR.employees e1, HR.employees e2 where e1.manager_id = e2.employee_id;

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:-

select e.department_id from HR.employees e, HR.departments d group by e.department_id having


e.department_id in e.department_id and count(*) is null;

no data found

You might also like