MySQL Tutorial
The AVG() function returns the average value of a numeric column.
SELECT AVG(column_name)
FROM table_name
WHERE condition;
Let's put these statements into real use.
We've a table named Students in our database that contains the following records:
ROLL_NO | NAME | SUBJECT |
---|---|---|
1 | Will | JAVA |
2 | SAM | Python |
3 | Sara | HTML | 4 | Rim | Java |
5 | Micheal | SQL |
6 | Lara | JAVA |
Now lets calculate the average number of record from Students table.
SELECT AVG(ROLL_NO)
FROM Students;
The above SELECT statement calculate the average number of ROLL_NO.
AVG(ROLL_NO) |
---|
3.5 |
We can calculate the average number of record with where condition.
SELECT AVG(ROLL_NO)
FROM Students;
WHERE SUBJECT='JAVA'
The above SELECT statement calculate the average number of SUBJECT is 'JAVA'.
AVG(ROLL_NO) |
---|
1 |