Professional Documents
Culture Documents
Moh&Ali
إهاء إWWW.ARAB
/OUG/HARDWARE/TEAM2000
3/21/2010
LES 06 Using Subqueries to Solve Queries
Practice 6
1.The HR department needs a query that prompts the user for an employee last name. The query then
displays the last name and hire date of any employee in the same department as the employee whose
name they supply (excluding that employee). For example, if the user enters Zlotkey, find all
employees who work with Zlotkey (excluding Zlotkey).
ل ان إدار إ
م: 1 ا"! ال#$
%&' (
) إدارة+,) -. د/" ا-
,01" -
" ا2.ور
../; ) د& ا
م45 ا
م/
. ة# آ7"8د9
ن
select last_name,hire_date,department_id
from employees
from employees
2. Create a report that displays the employee number and last name of all employees who earn
more than the average salary. Sort the results in order of ascending salary.
#=@ون ? أ8A. -.@" (B1 وا-
,01" ;وز ر= ا: 2 ا"! ال#$
. ? 1"!? ا$ /; .4;D E5
" ت ور? ا1" اG -
select employee_id,last_name
from employees
from employees)
order by salary;
3. Write a query that displays the employee number and last name of all employees who work in a
department with any employee whose last name contains a u. Place your SQL statement in a text file
named lab_06_03.sql. Run your query.
from employees
from employees
4.The HR department needs a report that displays the last name, department number, and job ID of all
employees whose department loca6on ID is 1700.
-
,01" اE,
0
ض ا ور= إدارة وو. . :4 ا"! ال#$
ه
وف ان1700
= = إدارة ر/) ن1
. -.@"ا
#1
P دارات )زمO ار=م ا= ا7 +
" -
,01"ول ا4
. داراتOول ا4 /; /; ,"
م اOا
select last_name,department_id,job_id
from employees
where department_id in (Select department_id
from departments
where location_id=1700)/
where location_id=&id);
5.Create a report for HR that displays the last name and salary of every employee who reports to King.
select last_name,salary
from employees
from employees
from employees
7.Modify the query in lab_06_03.sql to display the employee number, last name, and salary of all
employees who earn more than the average salary and who work in a department with any employee
whose last name contains a u. Resave lab_06_03.sql as lab_06_07.sql. Run the statement in lab_06_07.sql.
71 ا4$ (
) ( وادارG1" ا- /; ( ا/"ا
. U ف$ /)
select employee_id,last_name,salary,department_id
from employees
from employees)
from employees