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
Eliminating Growth Friction: How Enteros Aligns Database Performance, Cloud FinOps, and RevOps
- 28 January 2026
- Database Performance Management
Introduction For modern enterprises, growth is no longer limited by market demand alone—it is increasingly constrained by technology efficiency. As organizations scale digital platforms, launch new products, expand globally, and adopt AI-driven services, hidden friction inside their technology stack quietly erodes margins, slows execution, and undermines revenue outcomes. At the center of this friction sits … Continue reading “Eliminating Growth Friction: How Enteros Aligns Database Performance, Cloud FinOps, and RevOps”
AI SQL-Powered Database Management: Enteros’ Performance Intelligence Platform for Tech Enterprises
Introduction Technology enterprises today operate at unprecedented scale and speed. SaaS platforms, cloud-native applications, AI services, data marketplaces, and digital ecosystems now serve millions of users globally—often in real time. At the heart of this digital machinery lie databases. Databases power application responsiveness, AI pipelines, analytics engines, customer experiences, and revenue-generating workflows. Yet as technology … Continue reading “AI SQL-Powered Database Management: Enteros’ Performance Intelligence Platform for Tech Enterprises”
Keeping Operations Running at Scale: Enteros’ AIOps-Driven Database Performance Platform
- 27 January 2026
- Database Performance Management
Introduction In manufacturing plants and insurance enterprises alike, operational continuity is non-negotiable. A delayed production schedule, a failed claims transaction, or a slow underwriting system can ripple into lost revenue, regulatory exposure, and eroded customer trust. At the heart of these operations sit databases—quietly powering everything from shop-floor automation and supply chain planning to policy … Continue reading “Keeping Operations Running at Scale: Enteros’ AIOps-Driven Database Performance Platform”
Managing Real Estate Data at Scale: Enteros AI Platform for Database Performance and Cost Estimation
Introduction The real estate sector has undergone a dramatic digital transformation over the past decade. From commercial real estate (CRE) platforms and property management systems to residential marketplaces, smart buildings, and PropTech startups, modern real estate enterprises are now fundamentally data-driven organizations. Behind digital leasing platforms, pricing engines, tenant experience apps, IoT-enabled buildings, analytics dashboards, … Continue reading “Managing Real Estate Data at Scale: Enteros AI Platform for Database Performance and Cost Estimation”