Академический Документы
Профессиональный Документы
Культура Документы
Mustafa
إهاء إWWW.ARAB
/OUG/HARDWARE/TEAM2000
3/21/2010
LES 04 Reporting Aggregated Data
Using the Group Functions
Practice 4 :
Determine the validity of the following three statements. Circle either True or False.
-: ا
ال
أو
1. Group func*ons work across many rows to produce one result per group.
True/False
.(00
)"./)ا. "ن وا# ف%
&' (#) * ه اوال ا-1
2. Group func*ons include nulls in calcula*ons.
True/False
9":ت إ/" &9 / إ2"ر% ا45ن اوال ا* "ه ا8 . ( 67" )".8)ا. 2"ر% ا45ف ا#) * ه ا-2
. (count (*)) ام ااDE& " أ9 او،(?
ً @ "مBارغ ا& ار%= ا0 NVL) اا
'. "I مD= *ن اوال ا8 J") ( وذ./ )ا. * اوال اG "*' 'H Where ' ه ا-3
.* "رج اا ا8& اB") G Where امDE أL= L وWhere '. امDE" اI* H= / وHaving
4. Find the highest, lowest, sum, and average salary of all employees. Label the columns
Maximum, Minimum, Sum, and Average, respectively. Round your results to the nearest whole
number. Place your SQL statement in a text file named lab_04_04.sql.
اS=O5 و4I =) 4E اG: وG L%T"ت اP O UE وع وO(
وأOP أآL "وز آ: 4 ا
ال
. 0
ب دOB/
From Employees;
5. Modify the query in lab_04_04.sql to display the minimum, maximum, sum, and average salary
for each job type. Resave lab_04_04.sql as lab_04_05.sql. Run the statement in lab_04_05.sql.
G U59 4
الE &9 "ت9 &'*?م اEX( ا#= ه" "وز:5 ا
ال
....%T ا4Eام اDEY) "س اE '& أS Oا
from employees
group by (job_id);
6.Write a query to display the number of people with the same job.
.count ف دا#دارة ه" هX دا ا%T(' آ و#) &' اL%T "وز ع د ا: 6 ا
ال
from employees
group by job_id;
7.Determine the number of managers without lis*ng them. Label the column Number of Managers.
Hint: Use the MANAGER_ID column to determine the number of managers.
.Count م داD "I9 دارةX") L=O= ه" "وز د ا: 7 ا
ال
select count(distinct(manager_id))
from employees;
8.Find the difference between the highest and lowest salaries. Label the column DIFFERENCE.
.. S O B وأS O &' أL) قO% ه" "وز ا:8 ا
ال
from employees;
If you have time, complete the following exercises:
9.Create a report to display the manager number and the salary of the lowest-paid
employee for that manager. Exclude anyone whose manager is not known. Exclude any groups
where the minimum salary is $6,000 or less. Sort the output in descending order of salary.
طO#) واO= 4BO *)" S O B ه" "وز ا:9 ا
ال
select min(salary),manager_id
أو ="وىL B أS O B =ن أ/ " وB =ن/ O= ا4Bأن ر
from employees
.S O B"س اE '& أS O اG 6000
where manager_id is not null
group by manager_id
having min(salary)>6000
order by salary;
10.Create a query to display the total number of employees and, of that total, the number of
employees hired in 1995, 1996, 1997, and 1998. Create appropriate column headings.
1998،1997،1996،1995 &9 L=`' 'ب د ا*"ل ا: 10 ا ال
ى هB "D (# L=اااااااااااا ه" "وز. .
الE. 4I") واع
"Iط أOa * L= "وزS7 (Sum) وه& ااG) &'" اI ف دوالO* "") H%' P") &5P= E 9 * "وز د ا*"ل ا'& ا
a *لL."0 S7 SUM " دا9O S=O2 "I' S7 4I") اعG' bB اc%9 و4I* @? و1995 ف ا'& ا *ا ف#
S7 TO_CHAR(HIRE,’YYYY’) مD وe"@ اH%' G.O &5P= c) اL= "وز/// E OIa =م4"9 G') آ"ن هd=ا"ر
G' 1995 b" آL* اE &' b * داL."0 f:O) &5P= ا دىG' "ن# f= " * ا4I") ا.X ار)"ع اb' آ
ا9 O% S7 E " '& آI5P و1995 4I* E &' اL%T ه"وا د ا5P= ا"= دولG م5 SUM ا9 (1) ?@ 4Bر
b'59 4 ا4a دولL اL9"ن أ "ر# f c) S=O2 0ا..."5% اDecode داG' د هb )* اb" آ3 الH% اO9
COUNT> )اL%Tق " ا9 ه....5-6-7-8 ا4B& ر9 O()وSUM G)ر8 اd) &*= رO)ة وا وO9 0 ا...0أن ا
ا4B رG'7 TO_CHAR ' " & " أن9 "I) S= "ن# DECODE " واSUM "I9و& "ر/ دوال ا3 مD راحL=*)و
SUM دا1 b*'7 '9 0 G' هh و1 اG' " ه, ف )"وى ا'& )* ال# وDECODE ( اا# " ه1995 ?@
. وه`اااااااااااااا1995 E &9 * ا'& أL%T آ اG' ا"= وG
SELECT count(Employee_id),
sum(decode(to_char(hire_date,'yyyy'),1995,1,0)) "1995”,
sum(decode(to_char(hire_date,'yyyy'),1996,1,0)) "1996",
sum(decode(to_char(hire_date,'yyyy'),1997,1,0)) "1997",
sum(decode(to_char(hire_date,'yyyy'),1998,1,0)) "1998"
from employees ;
11. Create a matrix query to display the job, the salary for that job based on department number,
and the total salary for that job, for departments 20, 50, 80, and 90, giving each column an
appropriate heading.
......10 c *ا." أرIO# هh و10 سb") "" b "9 &' P# ةO9 :11 ا ال
select job_id,
sum(decode(department_id,20,salary,0)) "20”,
sum(decode(department_id,50,salary,0)) "50",
sum(decode(department_id,80,salary,0)) "80",
sum(decode(department_id,90,salary,0)) "90",
sum(salary) "TOTAL"
from employees
group by job_id,department_id;