
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get the Average of Average in a single MySQL row?
You can use aggregate function AVG() for this. Let us first create a table −
mysql> create table DemoTable ( Value1 int, Value2 int, Value3 int ); Query OK, 0 rows affected (0.54 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values(10,20,30); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values(13,15,18); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(21,31,41); Query OK, 1 row affected (0.21 sec)
Display records from the table using select command −
mysql> select *from DemoTable;
This will produce the following output −
+--------+--------+--------+ | Value1 | Value2 | Value3 | +--------+--------+--------+ | 10 | 20 | 30 | | 13 | 15 | 18 | | 21 | 31 | 41 | +--------+--------+--------+ 3 rows in set (0.00 sec)
Following is the query to display average of average in a single row −
mysql> select avg(Value1+Value2+Value3)/3.0 from DemoTable;
This will produce the following output −
+-------------------------------+ | avg(Value1+Value2+Value3)/3.0 | +-------------------------------+ | 22.11111111 | +-------------------------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- Get the average row length of a MySQL table
- Querying average row length in MySQL?
- MySQL query to calculate the average of values in a row?
- How to get the Average on MySQL time column?
- How do I get the average string length in MySQL?
- Get the average of marks in MongoDB with aggregate?
- Finding the average and display the maximum average of duplicate ids?
- Write a Python program to find the average of first row in a Panel
- Calculate average of numbers in a column MySQL query?
- Finding average marks of students for different subjects and display only the highest average marks in MySQL
- Create a MySQL function and find the average of values in a column
- Find average of a list in python?
- Find average of a list in Java
- Python program to get average heights of distinct entries
- Get only a single value from a specific MySQL row?
Advertisements