Returning the Average, Minimum, and Total Values with AVG( ), MIN( ), and SUM( ) : AVG « Aggregate Functions « SQL / MySQL






Returning the Average, Minimum, and Total Values with AVG( ), MIN( ), and SUM( )

      
mysql>
mysql>
mysql> CREATE TABLE sales_rep(
    ->   employee_number INT,
    ->   surname VARCHAR(40),
    ->   first_name VARCHAR(30),
    ->   commission TINYINT
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> INSERT INTO sales_rep values(4,'Rive','Mongane',10);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO sales_rep values(5,'Smith','Mike',12);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql>
mysql> SELECT AVG(commission) FROM sales_rep;
+-----------------+
| AVG(commission) |
+-----------------+
|         11.0000 |
+-----------------+
1 row in set (0.00 sec)

mysql>
mysql>
mysql> drop table sales_rep;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
    
  








Related examples in the same category

1.To display an average value of zero in that case, modify the query to test the value of AVG( ) with IFNULL( )
2.AVG() Function averages the values returned by a specified expression.
3.Get the average price
4.Average length
5.How much you paid for each author's books, in total and on average
6.Find the average sales amount per sales quarter.
7.How many miles did the drivers in the mytable table travel? What was the average miles traveled per day?