SQL SUM( ) Function


The SUM() Function

The SUM() function returns the total sum of a numeric column.

SQL SUM() Syntax

SELECT SUM(column_name) FROM table_name

SQL SUM() Example

We have the following "result" table:
Student_No
Subject_No
Year_Exam
Marks
ST101
SU03
1
69
ST102
SU01
1
61
ST101
SU04
1
70
ST101
SU05
1
87
ST103
SU01
2
51
ST103
SU03
1
59
ST103
SU01
3
56
ST108
SU01
1
78
ST105
SU05
2
98

Now we want to find the sum of all "Marks" .
We use the following SQL statement:

SELECT SUM(Marks) AS Total_Marks FROM result;

The result-set will look like this:
Total_Marks
        629

Post a Comment

Thank you for vising

أحدث أقدم