
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Find the average of column values in MySQL using aggregate function
Let us first create a table −
mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.79 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(78); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(91); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values(96); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Number | +--------+ | 56 | | 78 | | 89 | | 98 | | 91 | | 96 | +--------+ 6 rows in set (0.00 sec)
Following is the query to get the average of column values −
mysql> select (sum(Number)*(100))/(100+500) from DemoTable;
This will produce the following output −
+-------------------------------+ | (sum(Number)*(100))/(100+500) | +-------------------------------+ | 84.6667 | +-------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to add column values in MySQL without using aggregate function?
- Create a MySQL function and find the average of values in a column
- Get the maximum value of a column with MySQL Aggregate function
- MySQL Aggregate Function to find the number of occurrences?
- MySQL query to find the average of only first three values from a column with five values
- Using Aggregate function to fetch values from different tables in SAP
- Calculate average of column values and display the result with no decimals in MySQL
- Create an aggregate checksum of a column in MySQL
- Find average on the basis of corresponding duplicate VARCHAR values in MySQL
- Get the average of marks in MongoDB with aggregate?
- How can column data values of a table be compared using MySQL STRCMP() function?
- How to change the column names in R within aggregate function?
- Call aggregate function in sort order with MySQL
- Using an Aggregate function in SAP HANA
- How to find the column and row indices of values in a matrix using which function in R?

Advertisements