Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

2010

ORACLE Fundamental_ SQL 1‫  أ


 أوراآ‬

Moh&Ali
‫ إهاء إ‬WWW.ARAB
/OUG/HARDWARE/TEAM2000
3/21/2010
LES 07 Using the Set Operators

Pracce 7:

1.The HR department needs a list of department IDs for departments that do not contain the
job ID ST_CLERK. Use set operators to create this report.


‫ وز ارم ادارات دارات ا‬:1 ‫ اال‬
!"#‫ ه‬#‫ ه‬ST_CLERCK ‫ ى  و‬
‫ول‬%& '( ‫*ط‬+‫ ا‬,- './‫ و‬0!‫ول ا‬%1Union
.‫ادارات‬
select department_id
from departments
Union
select department_id
from employees
where job_id<>'ST_CLERCK';

2. The HR department needs a list of countries that have no departments located in them. Display
the country ID and the name of the countries. Use set operators to create this report.
‫د‬3‫ و‬4- ‫ش إدارات‬4( ‫د ا‬78‫"*ض ا‬3 ‫ وز‬:2 ‫ اال‬
4? ‫ وا<د ا;ص‬%8‫*ض ا>= ا‬
SQL> select country_id,country_name (‫رًا‬B"- ?&C‫ ا‬DB‫ ه‬E 0( FG ‫ = ا‬3 =)).
2 from countries
3 where country_id in (select country_id
4 from countries
5 minus select country_id
6 from locations);
CO COUNTRY_NAME
-- ----------------------------------------
AR Argentina
BE Belgium
DK Denmark
EG Egypt
FR France
HK HongKong
IL Israel
KW Kuwait
NG Nigeria
ZM Zambia
ZW Zimbabwe
3.Produce a list of jobs for departments 10, 50, and 20, in that order. Display job ID and
department ID using set operators.

'( ‫*ح < و‬P #‫"! ه‬#‫(ه‬50/20/10) ‫ ادارات‬- 4? 'G ‫ وأرم ادارات ا‬JK‫ ا*ض ا>!ء ا‬:3 ‫ اال‬
‫ ا‬G ‫ول ادارات‬%1- Q( ‫< أن‬+( #4&‫ول ادارات وه ا‬%& 0( =4*S/ 0!‫ول ا‬%& 0( 4 ‫ر= ادارة‬
.(Dummy) ‫رغ‬- ‫ !د‬,/<( '.#-

select job_id,department_id
from employees
where department_id in (10,20,50)
minus
select to_char(null),department_id
from departments;

4.Create a report that lists the employee IDs and job IDs of those employees who currently have a job
title that is the same as their job title when they were initially hired by the company (that is, they
changed jobs but have now gone back to doing their original job).

=V =4 #4( ‫*ت‬W ‫*آ اى‬+? 4? ‫أو‬%? ‫= ا‬4 #4( Y#- ‫ ا ?"!ا‬0!‫ ا‬JK‫ وز ارم وو‬:4 ‫ اال‬
.INTERSECT 'PG ‫ ا‬,- ‫م‬%; 3 ‫ا‬B4- ‫*ا‬Z‫ (*ة ا‬4 ‫دو‬

select employee_id,job_id
from employees
intersect
select employee_id,job_id
from job_history;
5. The HR department needs a report with the following specifications:

A-Last name and department ID of all the employees from the EMPLOYEES table, regardless of
whether or not they belong to a department

B- Department ID and department name of all the departments from the DEPARTMENTS table,
regardless of whether or not they have employees working in them

Write a compound query to accomplish this.

=4 ‫ وأرم إدارا‬0!‫ ?[>!ء ا‬3G #‫ وز ه‬:5 ‫ اال‬


0( 4- ‫ أ>!ء ادارات >اء آن‬،
‫= إدارة ام‬4 ‫>اء آن‬
.
‫أم‬

select last_name,department_id,to_char(null)
from employees
union all
select to_char(null),department_id,department_name
from departments

You might also like