Aggregation Operations in Relational Algebra
Aggregation operations are used to summarize data in a relation. Common aggregation functions include COUNT, SUM, AVG, MAX, MIN. These operations are essential for generating totals, averages, maximum or minimum values, and counts in datasets.
Common Aggregation Functions
- COUNT: Counts the number of tuples.
- SUM: Calculates the total of numeric attributes.
- AVG: Computes the average value of numeric attributes.
- MAX: Finds the maximum value.
- MIN: Finds the minimum value.
Example Dataset (Bangladeshi Data)
| Student | Course | Marks |
|---|---|---|
| Arif | DBMS | 85 |
| Arif | Networking | 90 |
| Rafi | DBMS | 78 |
| Rafi | Networking | 88 |
| Sadia | DBMS | 92 |
| Sadia | AI | 95 |
Example Queries and Results
1. Average Marks of Each Student
AVG(Marks) GROUP BY Student
| Student | Average Marks |
|---|---|
| Arif | 87.5 |
| Rafi | 83 |
| Sadia | 93.5 |
2. Maximum Marks in DBMS
MAX(Marks) WHERE Course='DBMS'
Result: 92
3. Total Marks of Arif
SUM(Marks) WHERE Student='Arif'
Result: 85 + 90 = 175
4. Count of Students per Course
COUNT(Student) GROUP BY Course
| Course | Number of Students |
|---|---|
| DBMS | 3 |
| Networking | 2 |
| AI | 1 |
Key Points
- Aggregation functions summarize numeric or countable data.
- GROUP BY is used to calculate aggregates per category.
- Aggregation is widely used in analytics, reporting, and dashboards.
Summary Table of Aggregation Functions
| Function | Description |
|---|---|
| COUNT | Counts number of tuples |
| SUM | Calculates total of numeric attribute |
| AVG | Calculates average value |
| MAX | Finds maximum value |
| MIN | Finds minimum value |
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন