PostgreSQL avg () function
The AVG function of PostgreSQL is used to find the average value of a field in various records.
To understand the AVG function, the table COMPANY has the following records:
Testdb # select * from COMPANY;
Id | name | age | address | salary
---- + ------- + ----- + ----------- + --------
1 | Paul | 32 | California | 20000
2 | Allen | 25 | TX | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall | 45000
7 | James | 24 | houaston | 10000
(7 rows)
Now, if you want to calculate the average salary based on the above table, you can use the following command: www.bkjia.com
Testdb = # select avg (SALARY) from company;
The above PostgreSQL table will produce the following results:
Avg
------------------
37142.8571428571
(1 row)
The average group by clause can be used to set various records. In the following example, all related records of a person are averaged, and the average salary of each person is calculated.
Testdb = # SELECT name, AVG (SALARY) from company group by name;
Name | avg
------- + -------
Teddy | 20000
Paul | 20000
Mark | 65000
David | 85000
Allen | 15000
Kim | 45000
James | 10000
(7 rows)
That which didn't kill me makes me stronger
For more MongoDB tutorials, see the following:
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here
This article permanently updates the link address: