سم الله الرحمن الرحيم
ربنا تقبل منا وتب علينا انك انت التواب الرحيم
Using the GROUP BY Clauseon

Multiple Columns
clause:فقرة
Multiple:متعدد
بالتأكيد يمكن التقسيم عن طريق اكثر من عمود بالتتابع حيث نقسم البيانات الى مجموعات عن طريق تقسيم العمود الاول ثم نقسم كل مجموعة من المجموعات الناتجه الى مجموعات هى الاخرى عن طريق تقسيم العمود الثانى وهكذا


*The GROUP BY clause specifies how you must group the rows:
– First, the rows are grouped by department number.
– Second, within the department number groups, the rows are grouped by job ID.
– So the SUM function is being applied to the salary column for all job IDs within each department number group.
illegal Queries Using Group Functions
illegal:غير صحيح او غير مسموح به




اما فى المثال التالى الخطأ فى اننا لا نستطيع استخدام where كالعادة فى وضع شروط على المجموعات والبديل هو استخدام having

Use the HAVING clause to restrict groups:
Restrict:يحد من او يقيد
نلاحظ ان المطلوب فى المثال السابق هو وضع شرط على المجموعات ان يكون متوسط المرتب فى المجموعة اكبر من 8000
وكلمة where لم تفى هنا بالغرض كما هو واضح فى النتائج
هنا يجب ان نستخدم كلمة having كالتالى :

تم تصغير هذه الصورة. إضغط هنا لرؤية الصورة كاملة. الحجم الأصلي للصورة هو 540 * 203.

مثال اخر على استخدام كلمة having:





Nesting Group Functions
Nesting:متداخل








Displaying Datafrom Multiple Tables
Sometimes you need to use data from more than one table. In the example, the report displays data from two separate tables
Separate:منفصل





• Employee IDs exist in the EMPLOYEES table.
• Department IDs exist in both the EMPLOYEES and DEPARTMENTS tables.
• ******** IDs exist in the DEPARTMENTS table.
To produce the report, you need to link the EMPLOYEES and DEPARTMENTS tables and access data from both of them.
Cartesian Products
يجب علينا عندما نريد بيانات من اكثر من جدول ان نربطهم معا برابط صحيح وسوف نتناول انواع الروابط فيما بعد وذلك حتى نضمن الناتج الصحيح
اذا لم نربط الجداول او نربطهم بطريقه خطأ تقوم قاعدة البيانات بضرب صفوف الجداول معا بالتبادل فيحدث خطأ فى النتائج
الخلاصة : مشكلة حاصل الضرب للصفوف فى الجدولين او اكثر تحدث عندما نربط الجدولين او اكثر برابط خطأ او لا نربطهم اصلا او ان هناك علاقه صحيحة اصلا بين كل الصفوف فى الجدولين وهنا لا تصبح مشكله


تم تصغير هذه الصورة. إضغط هنا لرؤية الصورة كاملة. الحجم الأصلي للصورة هو 510 * 285.

تم تصغير هذه الصورة. إضغط هنا لرؤية الصورة كاملة. الحجم الأصلي للصورة هو 520 * 165.

انواع الروابط :
لا يوجد فرق بين oracle joins و SQL1999 joins
فانت تستطيع ان ان تستخدم اى منهم اسهل بالنسبه لك






What is an Equijoin?



*To determine an employee’s department name, you compare the value in the DEPARTMENT_ID
column in the EMPLOYEES table with the DEPARTMENT_ID values in the DEPARTMENTS table.
Determine:يحدد
* Values in the DEPARTMENT_ID column on both tables must be equal. Frequently, this type of join involves primary and foreign key .
Frequently:بطريقه متكررة
Involves:يستخدم



• The SELECT clause specifies the column names to retrieve:
– employee last name, employee number, and department number, which are columns in the EMPLOYEES table
department number, department name, and ******** ID, which are columns in the DEPARTMENTS table
• The FROM clause specifies the two tables that the data**** must access:
EMPLOYEES table
DEPARTMENTS table
• The WHERE clause specifies how the tables are to be joined:
EMPLOYEES.DEPARTMENT_ID = DEPARTMENTS.DEPARTMENT_ID
Because the DEPARTMENT_ID column is common to both tables, it must be prefixed by
the table name to avoid ambiguity.

Ambiguous:غموض والتباس
Common:مشترك



Additional Search Conditions Using the AND Operator
For example, to display employee Matos’department number and department name, you need an additional condition in the WHERE clause




تم تصغير هذه الصورة. إضغط هنا لرؤية الصورة كاملة. الحجم الأصلي للصورة هو 510 * 143.

Using Table Aliases
Simplify queries by using table aliases.
Improve performance by using table prefixes.
Performance:أداء
Prefixes:بادئه الاسم



Joining More than Two Tables


تم تصغير هذه الصورة. إضغط هنا لرؤية الصورة كاملة. الحجم الأصلي للصورة هو 520 * 308.


To join n tables together, you need a minimum of n-1 join conditions. For example, to join three tables, a minimum of two joins is required.


For example, to display the last name, the department name, and the city for each employee, you have to join the EMPLOYEES, DEPARTMENTS, and ********S tables.



تم تصغير هذه الصورة. إضغط هنا لرؤية الصورة كاملة. الحجم الأصلي للصورة هو 510 * 255.