Relational Algebra
Q: Why is it called algebra?
A: Because there are operators and operands, the operand is a table, the operator is the intersection, and so on;
Relational algebra is divided into set-based relational algebra and packet-based relational algebra;
The basic operation of relational algebra: and, Selection, projection, Cartesian product, difference, renaming;
The basic operation means that other operators can be launched by basic operation;
Note: If we use the and, intersection, and difference operations, we must ensure that the properties set of R and S are the same, and of course, if they are different, they can also be renamed;
Add:
1. Natural Connection
2.θ Connection
3. renaming
An expression tree
Packet-based relational algebra
1. and
If the tuple T appears in R for M times and N times in S, it appears m+n times in R∪s;
2. Pay
If the tuple T appears in R for M times and N times in S, then min (m,n) appears in R∩s;
3. Poor
If the tuple T appears in R for M times and N times in S, then the r-s appears (1) if m>n, the m-n occurs; (2) if m<n, 0 times;
4. Eliminate duplicate operators
Δ (R) can eliminate repeating tuples on relation R;
5. Aggregation Operators
SUM (A)
AVG (A)
MIN (A)
MAX (A)
COUNT (A)
Where A is a property;
6. Grouping operators
Gamma
Contains a property as a grouping attribute, and an aggregation operator;
7. Sorting tuples
Τa (R) means sorting according to the A attribute;
8. External connection
left outer connection:
right outer connection:
9. Extended Projection Operations
Step representations of relational algebraic expressions
Because it is not clear that a complex algebraic expression is represented directly by an expression, we can express it in steps.
Like what:
Can be expressed as: