Presentation is loading. Please wait.

Presentation is loading. Please wait.

©Silberschatz, Korth and Sudarshan4.1Database System Concepts סכימה לדוגמא.

Similar presentations


Presentation on theme: "©Silberschatz, Korth and Sudarshan4.1Database System Concepts סכימה לדוגמא."— Presentation transcript:

1 ©Silberschatz, Korth and Sudarshan4.1Database System Concepts סכימה לדוגמא

2 ©Silberschatz, Korth and Sudarshan4.2Database System Concepts select * n צורה סטנדרטית של שאילתת SQL: select A 1, A 2, … חזרה from r 1, r 2, … where תנאי A k as A,..., r 3 as s,... having תנאי AggFunc(…) group by A a, A b … avg: average value min: minimum value max: maximum value sum: sum of values count: number of values

3 ©Silberschatz, Korth and Sudarshan4.3Database System Concepts select branch-name, avg (balance) from account group by branch-name פונקציות צבירה – פסוקית having n מצאו את שמות כל הסניפים שסכום כל החשבונות שבהם גדול מ-1200 ₪. הערה: התנאים בתוך פסוקית ה-having, מופעלים לאחר יצירת הקבוצות בעוד שהתנאים בפסוקית ה-where מופעלים עוד לפני יצירת הקבוצות select branch-name, avg (balance) from account group by branch-name having avg (balance) > 1200

4 ©Silberschatz, Korth and Sudarshan4.4Database System Concepts select D.customer-name, avg (balance) from depositor as D, account as A, customer as C whereD.acct-number = A.acct-number and D.cust-name = C.cust-name and C.city = “חיפה” group by D.cust-name having count (D.acct-number) > = 3 פונקציות צבירה – פסוקית having n מצאו את ממוצע מאזני החשבונות עבור כל לקוח הגר בחיפה, וקיימים עבורו לפחות 3 חשבונות

5 ©Silberschatz, Korth and Sudarshan4.5Database System Concepts ערכי Null n ייתכן כי בתוך רשומה יהיו ערכים ריקים, המסומנים כ-null, עבור כמה תכונות. Null משמעותו - ערך לא ידוע, או ערך לא קיים היחס is null – ניתן להשתמש בו כדי לבדוק קיום ערכי null H לדוגמא: מצאו את כל מספרי ההלוואה אשר מופיעים עם ערך null עבור סכום הלוואה select loan-number from loan where amount is null n תוצאת כל צירוף של ביטוי אריתמטי (חשבוני) עם ערך null מחזיר null  E.g. 5 + null returns null n פונקציות צבירה מתעלמות כמעט מערכי null H עוד קצת...

6 ©Silberschatz, Korth and Sudarshan4.6Database System Concepts ערכי Null ופונקציות צבירה n סכום כל ההלוואות select sum (amount) from loan H השאילתה מתעלמת לחלוטין מכל ערכי ה-null  התשובה היא null אם היו קיימים רק ערכי null. כל פונקציות הצבירה למעט count(*) מתעלמות לחלוטין מערכי null

7 ©Silberschatz, Korth and Sudarshan4.7Database System Concepts שאילתות מקוננות n ניתן ב-SQL להשתמש בשאילתות מקוננות n שאילתה מקוננת, היא תת-שאילתה במבנה הרגיל של select-from-where, אשר מהווה חלק משאילתה רחבה יותר n נלמד שימוש מיוחד בפסוקית in

8 ©Silberschatz, Korth and Sudarshan4.8Database System Concepts דוגמא n מצאו את כל הלקוחות אשר יש להם גם חשבון וגם הלוואה בבנק select distinct B.customer-name from borrower as B, depositor as D where B.customer-name = D.customer-name select distinct customer-name from borrower where customer-name in (select customer-name from depositor) סיבוכיות: O(M + N) סיבוכיות: O(M X N)

9 ©Silberschatz, Korth and Sudarshan4.9Database System Concepts דוגמא נוספת (select distinct customer-name from borrower ) פחות (select customer-name from depositor ) n מצאו את כל הלקוחות אשר להם יש הלוואה בבנק, אך אין להם חשבון בבנק select distinct customer-name from borrower where customer-name not in (select customer-name from depositor)


Download ppt "©Silberschatz, Korth and Sudarshan4.1Database System Concepts סכימה לדוגמא."

Similar presentations


Ads by Google