Articles → SQL SERVER → Aggregate Functions In SQL Server
Aggregate Functions In SQL Server
Purpose
- Sum
- Avg
- Max
- Count
Student, Subject and Marks tables
| Student_ID | Student_Name |
|---|
| 1 | Karan |
| 2 | Sumit |
| 3 | Ashish |
| Subject_ID | Subject_Name |
|---|
| 1 | Mathematics |
| 2 | Social Studies |
| 3 | General Science |
| Primary_Key_ID | Student_ID | Subject_ID | Marks |
|---|
| 1 | 1 | 1 | 85 |
| 2 | 1 | 2 | 65 |
| 3 | 1 | 3 | 60 |
Sum
select sum(Marks) from Marks where Student_ID = 1
Avg
select avg(Marks) from Marks where Student_ID = 1
Max
select max(Marks) from Marks where Student_ID = 1
Count
select count(*) from Marks where Student_ID = 1
| Posted By - | Karan Gupta |
| |
| Posted On - | Monday, March 29, 2010 |