RSS Feed

SQL AVG()

SQL AVG()

The AVG() function returns the Average of numeric column. SQL AVG() ignores Null Values.

Syntax of SQL AVG()

AVG ( [ ALL | DISTINCT ] expression )

Example 1 of SQL AVG()

From the Sal column, below query will show the AVG of all the values which are less than 25000

SELECT AVG(sal) as "Average Sal"
FROM emp
WHERE sal < 25000;


Example 2 of SQL AVG()

Below is the test_table (Number is an int type column):

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 AVG(all Number) from test_table

Result:
3

Select AVG(distinct Number) from test_table

Result:
4