close[x]


MySQL

MySQL-Home MySQL-Environment setup MySQL- Workbench MySQL-Basic syntax MySQL-Operator MySQL-Data type MySQL-Comments MySQL-Create DB MySQL-Drop DB MySQL-Select DB MySQL-Create Table MySQL-Drop table MySQL-Truncate MySQL-Primary Key MySQL-Foreign Key MySQL-Null MySQL-Increment MySQL-Having MySQL-Top MySQL-Insert Statement MySQL-Select Statement MySQL-Alter Statement MySQL-Where MySQL-And & Or MySQL-Default values MySQL-Exists MySQL-Order by MySQL-View MySQL-Update Statement MySQL-Delete Statement MySQL-Like MySQL-Sort MySQL-Limit MySQL-Min MySQL-Max MySQL-Group MySQL-In MySQL-Between MySQL-Union MySQL-Count MySQL-Average MySQL-Sum MySQL-Date & Time MySQL-Import MySQL-Export MySQL-Index MySQL-Temporary MySQL-Join MySQL-Full Join MySQL-Inner Join MySQL-Left Join MySQL-Right Join MySQL-Store Procedure MySQL-Injection MySQL-PHP connection



learncodehere.com



MySQL - AVG()

The AVG() function returns the average value of a numeric column.

Syntax : AVG()


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.

Example : AVG()



SELECT AVG(ROLL_NO)
FROM Students;
                

The above SELECT statement calculate the average number of ROLL_NO.

Result

AVG(ROLL_NO)
3.5

We can calculate the average number of record with where condition.

Example: AVG()


SELECT AVG(ROLL_NO)
FROM Students;
WHERE SUBJECT='JAVA'  

The above SELECT statement calculate the average number of SUBJECT is 'JAVA'.

Result

AVG(ROLL_NO)
1