Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Relational algebra
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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!
=== Operations for domain computations === There is nothing in relational algebra introduced so far that would allow computations on the data domains (other than evaluation of propositional expressions involving equality). For example, it is not possible using only the algebra introduced so far to write an expression that would multiply the numbers from two columns, e.g. a unit price with a quantity to obtain a total price. Practical query languages have such facilities, e.g. the SQL SELECT allows arithmetic operations to define new columns in the result <syntaxhighlight lang="sql" inline>SELECT unit_price * quantity AS total_price FROM t</syntaxhighlight>, and a similar facility is provided more explicitly by Tutorial D's <code>EXTEND</code> keyword.<ref name="Date2011">{{cite book|author=C. J. Date|title=SQL and Relational Theory: How to Write Accurate SQL Code|url=https://books.google.com/books?id=WuZGD5tBfMwC&pg=PA133|year=2011|publisher=O'Reilly Media, Inc.|isbn=978-1-4493-1974-8|pages=133β135}}</ref> In database theory, this is called '''extended projection'''.<ref name="Garcia-MolinaUllman2009"/>{{rp|213}} ==== 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" />
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Relational algebra
(section)
Add topic