PostgreSQL GROUP BY Clause
The PostgreSQL Group By statement is used to group identical values into summary rows such as "Search the number of users in each state". The GROUP BY statement is often used with aggregate functions and follows the WHERE clause in a select statement.For each group, an aggregate function like sum(), count () etc. can be applied.
GROUP BY Syntax :
The syntax of the GROUP BY statement is −
SELECT col_name, group_func(col_name) from employees group by col_name, [col_name]
GROUP BY Example :
Consider the STUDENT table is having the following records
TEST CASE 1 :- The following code is an example, which would fetch the all record from STUDENT table where AGE is greater equal to 20.
lfcdb=# SELECT ADDRESS, AVG(AGE) FROM STUDENT GROUP BY ADDRESS ORDER BY ADDRESS;
The result for the respective query is as follows −