Preamble
PostgreSQL GROUP BY statement is used in the SELECT statement to collect data on several records and group results by one or more columns.
The syntax for GROUP BY statement in PostgreSQL
SELECT expression1_id, expression2_id,. expression_n_id,
aggregate_function
FROM tabs
[WHERE conds]
GROUP BY expression1_id, expression2_id,. expression_n_id;
Parameters and arguments of the statement
- expression1_id, expression2_id,…_n_id – Expressions that are not enclosed in an aggregate function and must be included in the GROUP BY offer.
- aggregate_function – This may be an aggregate function, for example, sum, count, min, max, or avg.
- Tabs – Tables from which you want to get records. At least one table must be specified in the FROM operator.
- WHERE conds – Optional. The conditions that must be met for the records to be selected.
Example using the sum function
Let’s consider an example of PostgreSQL query GROUP BY, which uses the sum function.
In this PostgreSQL example of GROUP BY, the sum function is used to return department names and “Salaries for the department”.
SELECT department, sum(salary_id) AS "Salaries for department".
FROM empls
GROUP BY depart;
Since you specified one column (department field) in your SELECT operator that is not encapsulated in the sum function, you should use the GROUP BY operator. That’s why the department field should be specified in the GROUP BY operator.
Example using the count function
Let’s consider how we could use the GROUP BY operator with the count function.
In this GROUP BY example, the count function is used to return department and “Number of employees” that have status ‘Active’.
SELECT department, count(*) AS "Number of employees"
FROM empls
WHERE status = 'Active'
GROUP BY depart;
Example using min function
Let’s now see how we can use the GROUP BY operator with the min function.
In this GROUP BY example, the function min is used to return department names and “Lowest salary”.
SELECT depart, min(salary_id) AS "Lowest salary".
FROM empls
GROUP BY depart;
Example using max
Finally, let’s see how we can use the GROUP BY operator with the max function.
In this GROUP BY example, the function max is used to get the department name and “Highest salary”.
SELECT department, max(salary_id) AS "Highest salary".
FROM empls
GROUP BY depart;
PostgreSQL: Group By | Course
About Enteros
Enteros offers a patented database performance management SaaS platform. It proactively identifies root causes of complex business-impacting database scalability and performance issues across a growing number of clouds, RDBMS, NoSQL, and machine learning database platforms.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
Cost Attribution for Marketing Platforms: How Enteros AI SQL and AIOps Deliver Data Intelligence
- 18 March 2026
- Database Performance Management
Introduction The marketing sector has evolved into one of the most data-intensive domains in modern business. From digital advertising and customer segmentation to real-time personalization and omnichannel campaigns, marketing platforms today rely on complex technology ecosystems powered by massive volumes of data. Every click, impression, conversion, and interaction generates data that must be processed, analyzed, … Continue reading “Cost Attribution for Marketing Platforms: How Enteros AI SQL and AIOps Deliver Data Intelligence”
How Media Platforms Optimize Growth Management with Enteros Performance Management and Cost Attribution
Introduction The media industry has undergone a massive transformation in the past decade. From traditional broadcasting to digital-first ecosystems, media platforms now operate in a world driven by streaming services, real-time content delivery, personalized recommendations, and global audience engagement. Whether it’s video streaming, music platforms, online publishing, or digital advertising networks, modern media organizations rely … Continue reading “How Media Platforms Optimize Growth Management with Enteros Performance Management and Cost Attribution”
Driving Telecom Efficiency with Enteros Database Software, AIOps Platform, and Cost Estimation Intelligence
- 17 March 2026
- Database Performance Management
Introduction The telecommunications industry is at the center of global digital transformation. From enabling 5G connectivity and IoT ecosystems to supporting streaming platforms, cloud applications, and enterprise communications, telecom operators are responsible for managing vast, complex, and high-performance digital infrastructures. Behind every call, message, and data transaction lies a sophisticated network of databases, applications, and … Continue reading “Driving Telecom Efficiency with Enteros Database Software, AIOps Platform, and Cost Estimation Intelligence”
Modernizing Fashion Technology with Enteros Database Management, AIOps Platform, and Cloud FinOps
Introduction The fashion industry is no longer just about creativity, design, and seasonal trends—it is now deeply rooted in data, digital platforms, and technology-driven operations. From global e-commerce platforms and mobile shopping apps to supply chain systems, inventory management tools, and customer engagement platforms, fashion enterprises rely heavily on modern IT ecosystems to drive growth … Continue reading “Modernizing Fashion Technology with Enteros Database Management, AIOps Platform, and Cloud FinOps”