0% found this document useful (0 votes)
10 views

Compte rendu tp revision

The document contains SQL queries related to employee and country data, including descriptions of tables, selection of distinct job IDs, and employee details based on various conditions. It also includes salary statistics, hire dates, and filtering based on specific criteria. Overall, it provides a comprehensive overview of employee data management using SQL commands.
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)
10 views

Compte rendu tp revision

The document contains SQL queries related to employee and country data, including descriptions of tables, selection of distinct job IDs, and employee details based on various conditions. It also includes salary statistics, hire dates, and filtering based on specific criteria. Overall, it provides a comprehensive overview of employee data management using SQL commands.
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/ 36

Compte rendu tp revision

1)

SQL> describe employees

Name Null? Type

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

EMPLOYEE_ID NOT NULL NUMBER(6)

FIRST_NAME VARCHAR2(20)

LAST_NAME NOT NULL VARCHAR2(25)

EMAIL NOT NULL VARCHAR2(25)

PHONE_NUMBER VARCHAR2(20)

HIRE_DATE NOT NULL DATE

JOB_ID NOT NULL VARCHAR2(10)

SALARY NUMBER(8,2)

COMMISSION_PCT NUMBER(2,2)

MANAGER_ID NUMBER(6)

DEPARTMENT_ID NUMBER(4)

2)

SQL> select * from countries;

CO COUNTRY_NAME REGION_ID

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

AR Argentina 2

AU Australia 3

BE Belgium 1

BR Brazil 2

CA Canada 2

CH Switzerland 1

CN China 3

DE Germany 1

DK Denmark 1

EG Egypt 4
FR France 1

25 rows selected.

3)

SQL> select distinct job_id from employees;

JOB_ID

----------

AC_ACCOUNT

AC_MGR

AD_ASST

AD_PRES

AD_VP

FI_ACCOUNT

FI_MGR

HR_REP

IT_PROG

MK_MAN

MK_REP

JOB_ID

----------

PR_REP

PU_CLERK

PU_MAN

SA_MAN

SA_REP

SH_CLERK

ST_CLERK

ST_MAN
19 rows selected.

4)

SQL> select last_name||' ,'||first_name||' ,'|| job_id ||' ,'||salary||' ,'||nvl(commission_pct,0)||'


,'||department_id as "Détails Employés" from employees where department_id=20 or
department_id=50 or department_id=80;

Détails Employés

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

Weiss ,Matthew ,ST_MAN ,8000 ,0 ,50

Fripp ,Adam ,ST_MAN ,8200 ,0 ,50

Kaufling ,Payam ,ST_MAN ,7900 ,0 ,50

Vollman ,Shanta ,ST_MAN ,6500 ,0 ,50

Mourgos ,Kevin ,ST_MAN ,5800 ,0 ,50

Nayer ,Julia ,ST_CLERK ,3200 ,0 ,50

Mikkilineni ,Irene ,ST_CLERK ,2700 ,0 ,50

Landry ,James ,ST_CLERK ,2400 ,0 ,50

Markle ,Steven ,ST_CLERK ,2200 ,0 ,50

Bissot ,Laura ,ST_CLERK ,3300 ,0 ,50

Atkinson ,Mozhe ,ST_CLERK ,2800 ,0 ,50

Détails Employés

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

Marlow ,James ,ST_CLERK ,2500 ,0 ,50

Olson ,TJ ,ST_CLERK ,2100 ,0 ,50

Mallin ,Jason ,ST_CLERK ,3300 ,0 ,50

Rogers ,Michael ,ST_CLERK ,2900 ,0 ,50

Gee ,Ki ,ST_CLERK ,2400 ,0 ,50

Philtanker ,Hazel ,ST_CLERK ,2200 ,0 ,50

Ladwig ,Renske ,ST_CLERK ,3600 ,0 ,50

Stiles ,Stephen ,ST_CLERK ,3200 ,0 ,50

Seo ,John ,ST_CLERK ,2700 ,0 ,50

Patel ,Joshua ,ST_CLERK ,2500 ,0 ,50


Rajs ,Trenna ,ST_CLERK ,3500 ,0 ,50

Détails Employés

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

Davies ,Curtis ,ST_CLERK ,3100 ,0 ,50

Matos ,Randall ,ST_CLERK ,2600 ,0 ,50

Vargas ,Peter ,ST_CLERK ,2500 ,0 ,50

Russell ,John ,SA_MAN ,14000 ,.4 ,80

Partners ,Karen ,SA_MAN ,13500 ,.3 ,80

Errazuriz ,Alberto ,SA_MAN ,12000 ,.3 ,80

Cambrault ,Gerald ,SA_MAN ,11000 ,.3 ,80

Zlotkey ,Eleni ,SA_MAN ,10500 ,.2 ,80

Tucker ,Peter ,SA_REP ,10000 ,.3 ,80

Bernstein ,David ,SA_REP ,9500 ,.25 ,80

Hall ,Peter ,SA_REP ,9000 ,.25 ,80

81 rows selected.

5)

SQL> select employee_id ,last_name,first_name from employees where (job_id='ST_CLERK' or


job_id = 'ST_MAN') and salary>4000 and department_id=50;

EMPLOYEE_ID LAST_NAME FIRST_NAME

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

120 Weiss Matthew

121 Fripp Adam

122 Kaufling Payam

123 Vollman Shanta

124 Mourgos Kevin

6)

SQL> select last_name , salary from employees where salary > 12000;

LAST_NAME SALARY
------------------------- ----------

King 24000

Kochhar 17000

De Haan 17000

Greenberg 12008

Russell 14000

Partners 13500

Hartstein 13000

Higgins 12008

8 rows selected.

7)

SQL> select last_name ,salary from employees where salary not between 5000 and 1000

0;

LAST_NAME SALARY

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

King 24000

Kochhar 17000

De Haan 17000

Austin 4800

Pataballa 4800

Lorentz 4200

Greenberg 12008

Raphaely 11000

Khoo 3100

Baida 2900

Tobias 2800

LAST_NAME SALARY

------------------------- ----------
Himuro 2600

Colmenares 2500

Nayer 3200

Mikkilineni 2700

Landry 2400

Markle 2200

Bissot 3300

Atkinson 2800

Marlow 2500

Olson 2100

Mallin 3300

64 rows selected.

8)

SQL> select last_name ,salary from employees where salary>&sal;

Enter value for sal: 12000

old 1: select last_name ,salary from employees where salary>&sal

new 1: select last_name ,salary from employees where salary>12000

LAST_NAME SALARY

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

King 24000

Kochhar 17000

De Haan 17000

Greenberg 12008

Russell 14000

Partners 13500

Hartstein 13000

Higgins 12008

8 rows selected.
9)

SQL> select last_name ,department_id from employees where department_id=20 or depar

tment_id=50 order by last_name asc;

LAST_NAME DEPARTMENT_ID

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

Atkinson 50

Bell 50

Bissot 50

Bull 50

Cabrio 50

Chung 50

Davies 50

Dellinger 50

Dilly 50

Everett 50

Fay 20

LAST_NAME DEPARTMENT_ID

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

Feeney 50

Fleaur 50

Fripp 50

Gates 50

Gee 50

Geoni 50

Grant 50

Hartstein 20

Jones 50

Kaufling 50

Ladwig 50
LAST_NAME DEPARTMENT_ID

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

Landry 50

Mallin 50

Markle 50

Marlow 50

Matos 50

McCain 50

Mikkilineni 50

Mourgos 50

Nayer 50

OConnell 50

Olson 50

LAST_NAME DEPARTMENT_ID

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

Patel 50

Perkins 50

Philtanker 50

Rajs 50

Rogers 50

Sarchand 50

Seo 50

Stiles 50

Sullivan 50

Taylor 50

Vargas 50

LAST_NAME DEPARTMENT_ID

------------------------- -------------
Vollman 50

Walsh 50

Weiss 50

47 rows selected.

10)

SQL> select last_name Employee ,salary as " Monthly Salary" from employees where (s

alary between 5000 and 12000) and department_id=20 or department_id=50 ;

EMPLOYEE Monthly Salary

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

Weiss 8000

Fripp 8200

Kaufling 7900

Vollman 6500

Mourgos 5800

Nayer 3200

Mikkilineni 2700

Landry 2400

Markle 2200

Bissot 3300

Atkinson 2800

EMPLOYEE Monthly Salary

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

Marlow 2500

Olson 2100

Mallin 3300

Rogers 2900

Gee 2400

Philtanker 2200
Ladwig 3600

Stiles 3200

Seo 2700

Patel 2500

Rajs 3500

46 rows selected.

11)

SQL> select last_name ,salary ,commission_pct from employees where commission_pct is not
null order by salary desc , commission_pct desc;

LAST_NAME SALARY COMMISSION_PCT

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

Russell 14000 .4

Partners 13500 .3

Errazuriz 12000 .3

Ozer 11500 .25

Cambrault 11000 .3

Abel 11000 .3

Vishney 10500 .25

Zlotkey 10500 .2

King 10000 .35

Tucker 10000 .3

Bloom 10000 .2

35 rows selected.

12)

SQL> select last_name ,hire_date from employees where hire_date between '01-JAN-200

2' and '31-DEC-2003';


LAST_NAME HIRE_DATE

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

King 17-JUN-03

Greenberg 17-AUG-02

Faviet 16-AUG-02

Raphaely 07-DEC-02

Khoo 18-MAY-03

Kaufling 01-MAY-03

Ladwig 14-JUL-03

Rajs 17-OCT-03

Whalen 17-SEP-03

Mavris 07-JUN-02

Baer 07-JUN-02

LAST_NAME HIRE_DATE

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

Higgins 07-JUN-02

Gietz 07-JUN-02

13 rows selected.

13)

SQL> select last_name from employees where last_name like '%a%' and last_name like

'%e%';

LAST_NAME

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

Baer

Bates

Colmenares

Davies
De Haan

Faviet

Fleaur

Gates

Hartstein

Markle

Nayer

LAST_NAME

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

Partners

Patel

Philtanker

Raphaely

Sewall

Whalen

17 rows selected.

14)

SQL> select last_name,months_between(sysdate,hire_date) as "Months worked" from emp

loyees order by months_between(sysdate,hire_date) desc;

LAST_NAME Months worked

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

De Haan 285.789076

Gietz 268.982624

Baer 268.982624

Mavris 268.982624

Higgins 268.982624

Faviet 266.692302
Greenberg 266.660044

Raphaely 262.982624

Kaufling 258.176173

Khoo 257.627786

King 256.660044

LAST_NAME Months worked

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

Ladwig 255.756818

Whalen 253.660044

Rajs 252.660044

Sarchand 249.337463

King 249.240689

Bell 249.079399

Hartstein 248.660044

Sully 248.079399

Abel 245.853592

Mallin 244.756818

Weiss 243.627786

LAST_NAME Months worked

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

McEwen 243.176173

Russell 241.176173

Partners 238.04714

Davies 237.272947

Tucker 237.240689

Marlow 236.692302

Bull 236.563269

Everett 236.111657

Smith 235.88585
Errazuriz 235.88585

Ozer 235.853592

107 rows selected.

15)

SQL> select last_name,hire_date,next_day(add_months(hire_date,3),'SUNDAY') Eval fr

om employees;

LAST_NAME HIRE_DATE EVAL

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

King 17-JUN-03 21-SEP-03

Kochhar 21-SEP-05 25-DEC-05

De Haan 13-JAN-01 15-APR-01

Hunold 03-JAN-06 09-APR-06

Ernst 21-MAY-07 26-AUG-07

Austin 25-JUN-05 02-OCT-05

Pataballa 05-FEB-06 07-MAY-06

Lorentz 07-FEB-07 13-MAY-07

Greenberg 17-AUG-02 24-NOV-02

Faviet 16-AUG-02 17-NOV-02

Chen 28-SEP-05 01-JAN-06

LAST_NAME HIRE_DATE EVAL

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

Sciarra 30-SEP-05 01-JAN-06

Urman 07-MAR-06 11-JUN-06

Popp 07-DEC-07 09-MAR-08

Raphaely 07-DEC-02 09-MAR-03

Khoo 18-MAY-03 24-AUG-03

Baida 24-DEC-05 26-MAR-06

Tobias 24-JUL-05 30-OCT-05


Himuro 15-NOV-06 18-FEB-07

Colmenares 10-AUG-07 11-NOV-07

Weiss 18-JUL-04 24-OCT-04

Fripp 10-APR-05 17-JUL-05

LAST_NAME HIRE_DATE EVAL

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

Kaufling 01-MAY-03 03-AUG-03

Vollman 10-OCT-05 15-JAN-06

Mourgos 16-NOV-07 17-FEB-08

Nayer 16-JUL-05 23-OCT-05

Mikkilineni 28-SEP-06 31-DEC-06

Landry 14-JAN-07 15-APR-07

Markle 08-MAR-08 15-JUN-08

Bissot 20-AUG-05 27-NOV-05

Atkinson 30-OCT-05 05-FEB-06

Marlow 16-FEB-05 22-MAY-05

Olson 10-APR-07 15-JUL-07

107 rows selected.

16)

SQL> select round(max(salary)) as "le salaire maximum" ,round(min(salary)) as "le salaire


minimum" ,round(sum(salary)) as "la masse salariale",round(avg(salary)) as "le salaire moyen"
from employees;

le salaire maximum le salaire minimum la masse salariale le salaire moyen

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

24000 2100 691416 6462

17)

SQL> select max(salary)-min(salary) Difference from employees;

DIFFERENCE
----------

21900

18)

SQL> select min(salary),max(salary),sum(salary) ,avg(salary) from employees group b

y job_id;

MIN(SALARY) MAX(SALARY) SUM(SALARY) AVG(SALARY)

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

4200 9000 28800 5760

12008 12008 12008 12008

8300 8300 8300 8300

5800 8200 36400 7280

11000 11000 11000 11000

4400 4400 4400 4400

17000 17000 34000 17000

2500 4200 64300 3215

6900 9000 39600 7920

12008 12008 12008 12008

2500 3100 13900 2780

MIN(SALARY) MAX(SALARY) SUM(SALARY) AVG(SALARY)

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

10500 14000 61000 12200

13000 13000 13000 13000

10000 10000 10000 10000

24000 24000 24000 24000

6100 11500 250500 8350

6000 6000 6000 6000

2100 3600 55700 2785

6500 6500 6500 6500


19 rows selected.

19)

SQL> select d.department_name from departments d join employees e on


e.department_id=d.department_id group by d.department_name having count
(e.employee_id)>20 ;

DEPARTMENT_NAME

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

Shipping

Sales

20)

SQL> select count(distinct manager_id ) from employees;

COUNT(DISTINCTMANAGER_ID)

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

18

21)

SQL> select last_name,job_id from employees

2 where manager_id is null;

LAST_NAME JOB_ID

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

King AD_PRES

22)

SQL> select manager_id,min(salary) from employees where manager_id is not null group by
manager_id having min(salary)>6000 order by min(salary) desc;

MANAGER_ID MIN(SALARY)

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

102 9000
205 8300

145 7000

146 7000

108 6900

147 6200

149 6200

148 6100

8 rows selected.

23)

SQL> select e.employee_id ,e.last_name, d.department_name from employees e join


departments d on e.department_id =d.department_id;

EMPLOYEE_ID LAST_NAME DEPARTMENT_NAME

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

200 Whalen Administration

201 Hartstein Marketing

202 Fay Marketing

114 Raphaely Purchasing

115 Khoo Purchasing

116 Baida Purchasing

117 Tobias Purchasing

118 Himuro Purchasing

119 Colmenares Purchasing

203 Mavris Human Resources

120 Weiss Shipping

EMPLOYEE_ID LAST_NAME DEPARTMENT_NAME

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

121 Fripp Shipping

122 Kaufling Shipping


123 Vollman Shipping

124 Mourgos Shipping

125 Nayer Shipping

126 Mikkilineni Shipping

127 Landry Shipping

128 Markle Shipping

129 Bissot Shipping

130 Atkinson Shipping

131 Marlow Shipping

106 rows selected.

24)

SQL> select d.department_name,l.street_address,l.postal_code ,l.city,l.state

_province,c.country_name from departments d join locations l on d.location_i

d=l.location_id join countries c on c.country_id=l.country_id;

DEPARTMENT_NAME STREET_ADDRESS

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

POSTAL_CODE CITY STATE_PROVINCE

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

COUNTRY_NAME

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

IT 2014 Jabberwocky Rd

26192 Southlake Texas

United States of America

Shipping 2011 Interiors Blvd

99236 South San Francisco California

United States of America


DEPARTMENT_NAME STREET_ADDRESS

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

POSTAL_CODE CITY STATE_PROVINCE

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

COUNTRY_NAME

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

Administration 2004 Charade Rd

98199 Seattle Washington

United States of America

Purchasing 2004 Charade Rd

98199 Seattle Washington

DEPARTMENT_NAME STREET_ADDRESS

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

POSTAL_CODE CITY STATE_PROVINCE

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

COUNTRY_NAME

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

United States of America

Executive 2004 Charade Rd

98199 Seattle Washington

United States of America

Finance 2004 Charade Rd

DEPARTMENT_NAME STREET_ADDRESS

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

POSTAL_CODE CITY STATE_PROVINCE


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

COUNTRY_NAME

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

98199 Seattle Washington

United States of America

Accounting 2004 Charade Rd

98199 Seattle Washington

United States of America

DEPARTMENT_NAME STREET_ADDRESS

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

POSTAL_CODE CITY STATE_PROVINCE

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

COUNTRY_NAME

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

Treasury 2004 Charade Rd

98199 Seattle Washington

United States of America

Corporate Tax 2004 Charade Rd

98199 Seattle Washington

United States of America

DEPARTMENT_NAME STREET_ADDRESS

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

POSTAL_CODE CITY STATE_PROVINCE

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

COUNTRY_NAME

----------------------------------------
Control And Credit 2004 Charade Rd

98199 Seattle Washington

United States of America

Shareholder Services 2004 Charade Rd

98199 Seattle Washington

DEPARTMENT_NAME STREET_ADDRESS

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

POSTAL_CODE CITY STATE_PROVINCE

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

COUNTRY_NAME

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

United States of America

Benefits 2004 Charade Rd

98199 Seattle Washington

United States of America

Manufacturing 2004 Charade Rd

DEPARTMENT_NAME STREET_ADDRESS

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

POSTAL_CODE CITY STATE_PROVINCE

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

COUNTRY_NAME

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

98199 Seattle Washington

United States of America


Construction 2004 Charade Rd

98199 Seattle Washington

United States of America

DEPARTMENT_NAME STREET_ADDRESS

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

POSTAL_CODE CITY STATE_PROVINCE

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

COUNTRY_NAME

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

Contracting 2004 Charade Rd

98199 Seattle Washington

United States of America

Operations 2004 Charade Rd

98199 Seattle Washington

United States of America

DEPARTMENT_NAME STREET_ADDRESS

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

POSTAL_CODE CITY STATE_PROVINCE

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

COUNTRY_NAME

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

IT Support 2004 Charade Rd

98199 Seattle Washington

United States of America

NOC 2004 Charade Rd


98199 Seattle Washington

DEPARTMENT_NAME STREET_ADDRESS

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

POSTAL_CODE CITY STATE_PROVINCE

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

COUNTRY_NAME

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

United States of America

IT Helpdesk 2004 Charade Rd

98199 Seattle Washington

United States of America

Government Sales 2004 Charade Rd

27 rows selected.

25)

SQL> select m.last_name ,e.last_name from employees m join employees e on m.employee_id


=e.manager_id where e.manager_id=101;

LAST_NAME LAST_NAME

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

Kochhar Greenberg

Kochhar Whalen

Kochhar Mavris

Kochhar Baer

Kochhar Higgins
26)

SQL> select e.last_name,e.first_name,e.job_id ,d.department_id ,d.department_name from


employees e join departments d on e.department_id=d.department_id join locations l on
l.location_id=d.location_id where l.city='London' order by d.department_name asc ;

LAST_NAME FIRST_NAME JOB_ID DEPARTMENT_ID

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

DEPARTMENT_NAME

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

Mavris Susan HR_REP 40

Human Resources

27)

SQL> select last_name || first_name , round (months_between(sysdate,hire_date)) from


employees where department_id =90 order by round (months_between(sysdate,hire_date))
desc;

LAST_NAME||FIRST_NAME

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

ROUND(MONTHS_BETWEEN(SYSDATE,HIRE_DATE))

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

De HaanLex

286

KingSteven

257

KochharNeena

230

28)

SQL> select sum(salary) from employees group by department_id, job_id order

by job_id ;
SUM(SALARY)

-----------

8300

12008

4400

24000

34000

39600

12008

6500

28800

13000

6000

SUM(SALARY)

-----------

10000

13900

11000

61000

243500

7000

64300

55700

36400

20 rows selected.

29)

SQL> select last_name,first_name ,salary from employees where salary> (selec

t max(salary) from employees where job_id like '%PROG');


LAST_NAME FIRST_NAME SALARY

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

King Steven 24000

Kochhar Neena 17000

De Haan Lex 17000

Greenberg Nancy 12008

Raphaely Den 11000

Russell John 14000

Partners Karen 13500

Errazuriz Alberto 12000

Cambrault Gerald 11000

Zlotkey Eleni 10500

Tucker Peter 10000

LAST_NAME FIRST_NAME SALARY

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

Bernstein David 9500

King Janette 10000

Sully Patrick 9500

Vishney Clara 10500

Greene Danielle 9500

Ozer Lisa 11500

Bloom Harrison 10000

Fox Tayler 9600

Abel Ellen 11000

Hartstein Michael 13000

Baer Hermann 10000

LAST_NAME FIRST_NAME SALARY

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


Higgins Shelley 12008

23 rows selected.

30)

SQL> select salary as "salaire mensuel" , (salary* 12) + (salary* NVL(commission_pct, 0)) as
"salaire annuel" from employees order by 'salaire annuel' desc;

salaire mensuel salaire annuel

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

24000 288000

17000 204000

17000 204000

9000 108000

6000 72000

4800 57600

4800 57600

4200 50400

12008 144096

9000 108000

8200 98400

107 rows selected.

31)

SQL> select e.employee_id , e.last_name,e.salary,d.department_name from employees e join


departments d on d.department_id=e.department_id where e.manage

r_id=&manager order by &col ;

Enter value for manager: 100

Enter value for col: e.salary

old 1: select e.employee_id , e.last_name,e.salary,d.department_name from employees e join


departments d on d.department_id=e.department_id where e.manager_id=&manager order by
&col

new 1: select e.employee_id , e.last_name,e.salary,d.department_name from employees e join


departments d on d.department_id=e.department_id where e.manager_id=100 order by e.salary
EMPLOYEE_ID LAST_NAME SALARY DEPARTMENT_NAME

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

124 Mourgos 5800 Shipping

123 Vollman 6500 Shipping

122 Kaufling 7900 Shipping

120 Weiss 8000 Shipping

121 Fripp 8200 Shipping

149 Zlotkey 10500 Sales

114 Raphaely 11000 Purchasing

148 Cambrault 11000 Sales

147 Errazuriz 12000 Sales

201 Hartstein 13000 Marketing

146 Partners 13500 Sales

EMPLOYEE_ID LAST_NAME SALARY DEPARTMENT_NAME

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

145 Russell 14000 Sales

101 Kochhar 17000 Executive

102 De Haan 17000 Executive

14 rows selected.

32)

SQL> select job_id,count(*) from employees group by job_id;

JOB_ID COUNT(*)

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

AC_ACCOUNT 1

AC_MGR 1

AD_ASST 1

AD_PRES 1
AD_VP 2

FI_ACCOUNT 5

FI_MGR 1

HR_REP 1

IT_PROG 5

MK_MAN 1

MK_REP 1

JOB_ID COUNT(*)

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

PR_REP 1

PU_CLERK 5

PU_MAN 1

SA_MAN 5

SA_REP 30

SH_CLERK 20

ST_CLERK 20

ST_MAN 5

19 rows selected.

33)

SQL> select e.last_name , e.first_name , jg.grade_level from employees e join job_grades jg on


e.salary between jg.lowest_sal and jg.highest_sal;

LAST_NAME FIRST_NAME GRA

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

Olson TJ A

Markle Steven A

Philtanker Hazel A

Landry James A

Gee Ki A

Colmenares Karen A
Marlow James A

Patel Joshua A

Vargas Peter A

Sullivan Martha A

Perkins Randall A

LAST_NAME FIRST_NAME GRA

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

Himuro Guy A

Matos Randall A

OConnell Donald A

Grant Douglas A

Mikkilineni Irene A

Seo John A

Tobias Sigal A

Atkinson Mozhe A

Geoni Girard A

Jones Vance A

Baida Shelli A

107 rows selected.

34)

SQL> select e.employee_id as emp, e.last_name as employee, m.employee_id as mgr,


m.last_name as manager from employees e left join employees m on e.manager_id =
m.employee_id;

EMP EMPLOYEE MGR MANAGER

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

173 Kumar 148 Cambrault

172 Bates 148 Cambrault

171 Smith 148 Cambrault

170 Fox 148 Cambrault


169 Bloom 148 Cambrault

168 Ozer 148 Cambrault

103 Hunold 102 De Haan

167 Banda 147 Errazuriz

166 Ande 147 Errazuriz

165 Lee 147 Errazuriz

164 Marvins 147 Errazuriz

EMP EMPLOYEE MGR MANAGER

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

163 Greene 147 Errazuriz

162 Vishney 147 Errazuriz

187 Cabrio 121 Fripp

186 Dellinger 121 Fripp

185 Bull 121 Fripp

184 Sarchand 121 Fripp

132 Olson 121 Fripp

131 Marlow 121 Fripp

130 Atkinson 121 Fripp

129 Bissot 121 Fripp

113 Popp 108 Greenberg

107 rows selected.

35)

SQL> select e1.last_name , e1.hire_date from employees e1 join employees e2 on e2.last_name


= 'Davies' where e1.hire_date > e2.hire_date;

LAST_NAME HIRE_DATE

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

Kochhar 21-SEP-05

Hunold 03-JAN-06

Ernst 21-MAY-07

Austin 25-JUN-05
Pataballa 05-FEB-06

Lorentz 07-FEB-07

Chen 28-SEP-05

Sciarra 30-SEP-05

Urman 07-MAR-06

Popp 07-DEC-07

Baida 24-DEC-05

81 rows selected.

36)

SQL> select last_name,hire_date from employees where hire_date>(select hire_date from


employees where last_name='Davies');

LAST_NAME HIRE_DAT

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

Feeney 23/05/06

OConnell 21/06/07

Grant 13/01/08

Fay 17/08/05

81 rows selected.

37)

SQL> select e.employee_id, e.last_name, e.salary from employees e where e.salary > (select
avg(salary) from employees) and e.department_id in (select department_id from employees
where lower(last_name) like '%e%');

EMPLOYEE_ID LAST_NAME SALARY

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

177 Livingston 8400

176 Taylor 8600

175 Hutton 8800

174 Abel 11000

172 Bates 7300


171 Smith 7400

170 Fox 9600

169 Bloom 10000

168 Ozer 11500

165 Lee 6800

164 Marvins 7200

49 rows selected.

38)

SQL> select e.last_name, e.hire_date , m.last_name , m.hire_date from employees e join


employees m on e.manager_id = m.employee_id where e.hire_date < m.hire_date;

LAST_NAME HIRE_DATE LAST_NAME HIRE_DATE

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

Kaufling 01-MAY-03 King 17-JUN-03

Raphaely 07-DEC-02 King 17-JUN-03

De Haan 13-JAN-01 King 17-JUN-03

Higgins 07-JUN-02 Kochhar 21-SEP-05

Baer 07-JUN-02 Kochhar 21-SEP-05

Mavris 07-JUN-02 Kochhar 21-SEP-05

Whalen 17-SEP-03 Kochhar 21-SEP-05

Greenberg 17-AUG-02 Kochhar 21-SEP-05

Austin 25-JUN-05 Hunold 03-JAN-06

Faviet 16-AUG-02 Greenberg 17-AUG-02

Bull 20-FEB-05 Fripp 10-APR-05

37 rows selected.

39)

SQL> select e.last_name, e.salary from employees e join employees m on e.ma

nager_id = m.employee_id where m.last_name = 'King';

LAST_NAME SALARY
------------------------- ----------

Kochhar 17000

De Haan 17000

Raphaely 11000

Weiss 8000

Fripp 8200

Kaufling 7900

Vollman 6500

Mourgos 5800

Russell 14000

Partners 13500

Errazuriz 12000

LAST_NAME SALARY

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

Cambrault 11000

Zlotkey 10500

Hartstein 13000

14 rows selected.

40)

SQL> select last_name,hire_date from employees where department_id=(select department_id


from employees where last_name='&&nom') and last_name<>'&nom';

Enter value for nom: Zlotkey

old 1: select last_name,hire_date from employees where department_id=(select department_id


from employees where last_name='&&nom') and last_name<>'&nom'

new 1: select last_name,hire_date from employees where department_id=(select


department_id from employees where last_name='Zlotkey') and last_name<>'Zlotkey'

LAST_NAME HIRE_DAT

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

Ozer 11/03/05

Bloom 23/03/06
Fox 24/01/06

Smith 23/02/07

Bates 24/03/07

Kumar 21/04/08

Abel 11/05/04

Hutton 19/03/05

Taylor 24/03/06

Livingston 23/04/06

Johnson 04/01/08

33 rows selected.

You might also like