1 / 15

Example

Example. Example. Example. Extended Relational-Algebra-Operations. Generalized Projection Aggregate Functions Outer Join. Generalized Projection. Extends the projection operation by allowing arithmetic functions to be used in the projection list. E is any relational-algebra expression

Download Presentation

Example

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Example

  2. Example

  3. Example

  4. Extended Relational-Algebra-Operations • Generalized Projection • Aggregate Functions • Outer Join

  5. Generalized Projection • Extends the projection operation by allowing arithmetic functions to be used in the projection list. • E is any relational-algebra expression • Each of F1, F2, …, Fnare are arithmetic expressions involving constants and attributes in the schema of E. • Given relation credit_info(customer_name, limit, credit_balance), find how much more each person can spend: customer_name, limit – credit_balance (credit_info)

  6. Aggregate Functions and Operations • Aggregation function takes a collection of values and returns a single value as a result. avg: average valuemin: minimum valuemax: maximum valuesum: sum of valuescount: number of values • Aggregate operation in relational algebra E is any relational-algebra expression • Each Fiis an aggregate function • Each Aiis an attribute name

  7. Aggregate Operation – Example • Relation r: A B C         7 7 3 10 • gsum(c) (r) sum(c ) 27

  8. pt_works relation • Find out the total sum of salaries of all the part time employees in the bank. gsum(salary) (pt_works) • Find out the total no. of branches appearing in the pt_works relation. gcount (distinct(branch_name)) (pt_works)

  9. Aggregate Functions and Operations • Aggregate operation in relational algebra using group E is any relational-algebra expression • G1, G2 …, Gn is a list of attributes on which to group (can be empty) • Each Fiis an aggregate function • Each Aiis an attribute name

  10. Aggregate Operation – Example • Relation account grouped by branch-name: branch_name account_number balance Perryridge Perryridge Brighton Brighton Redwood A-102 A-201 A-217 A-215 A-222 400 900 750 750 700 branch_nameg sum(balance) (account) branch_name sum(balance) Perryridge Brighton Redwood 1300 1500 700

  11. Example query • Find out the maximum salary for part-time employees at each branch, in addition to the sum of salaries branch_nameg sum(salary), max(salary) (pt_works)

  12. Aggregate Functions (Cont.) • Result of aggregation does not have a name • Can use rename operation to give it a name • For convenience, we permit renaming as part of aggregate operation branch_nameg sum(balance) as sum_balance (account)

  13. Example branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) account (account_number, branch_name, balance) depositor (customer_name, account_number) Find the accounts held by more than two customers using an aggregate function.

  14. Example • Find the company with the most employees • Find the company with the smallest payroll

  15. Example • Find the company with the most employees • Find the company with the smallest payroll

More Related