RSS Feed

SQL SUM()

SQL SUM()

The SUM() function returns the sum of numeric column. SQL SUM() ignores Null Values.

Syntax of SQL SUM()

SUM ( [ ALL | DISTINCT ] expression )

Example 1 of SQL SUM()

From the Sal column, below query will sum all the values which are less than 25000

SELECT SUM(sal) as "Total Sal"
FROM emp
WHERE sal < 25000;


Example 2 of SQL SUM()

Below is the test_table:

IDNumber
11
21
31
41
52
62
72
82
93
103
113
123
134
144
154
164
175
185
195
206
216
226
232
242
257
267
277
285
297
30 5
315
322
335
342
352

Below are the queries run on this above table with their results:

Select Sum(all Number) from test_table

Result:
131

Select Sum(distinct Number) from test_table

Result:
28

No comments:

Post a Comment