Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Relational algebra
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Aggregation ==== Furthermore, computing various functions on a column, like the summing up of its elements, is also not possible using the relational algebra introduced so far. There are five [[aggregate function]]s that are included with most relational database systems. These operations are Sum, Count, Average, Maximum and Minimum. In relational algebra the aggregation operation over a schema (''A''<sub>1</sub>, ''A''<sub>2</sub>, ... ''A''<sub>''n''</sub>) is written as follows: :<math>G_1, G_2, \ldots, G_m\ g_{f_1({A_1}'), f_2({A_2}'), \ldots, f_k({A_k}')}\ (r)</math> where each ''A''<sub>''j''</sub>', 1 β€ ''j'' β€ ''k'', is one of the original attributes ''A''<sub>''i''</sub>, 1 β€ ''i'' β€ ''n''. The attributes preceding the ''g'' are grouping attributes, which function like a "group by" clause in SQL. Then there are an arbitrary number of aggregation functions applied to individual attributes. The operation is applied to an arbitrary relation ''r''. The grouping attributes are optional, and if they are not supplied, the aggregation functions are applied across the entire relation to which the operation is applied. Let's assume that we have a table named {{mono|Account}} with three columns, namely {{mono|Account_Number, Branch_Name}} and {{mono|Balance}}. We wish to find the maximum balance of each branch. This is accomplished by <sub>{{mono|Branch_Name}}</sub>''G''<sub>Max({{mono|Balance}})</sub>({{mono|Account}}). To find the highest balance of all accounts regardless of branch, we could simply write ''G''<sub>Max({{mono|Balance}})</sub>({{mono|Account}}). Grouping is often written as <sub>{{mono|Branch_Name}}</sub>''Ι£''<sub>Max({{mono|Balance}})</sub>({{mono|Account}}) instead.<ref name="Garcia-MolinaUllman2009" />
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)