Aggregate functions compute a single result from a set of rows. PostgreSQL provides a rich set of built-in aggregates. Common Aggregate Functions Function Purpose COUNT() Number of rows COUNT(col) Non-null values in column SUM(col) Total of numeric column AVG(col) Average value MIN(col) / MAX(col) Smallest / largest value STRINGAGG(col, sep) Concatenate strings ARRAYAGG(col) Collect values into array BOOLAND(col) / BOOLOR(col) Logical aggregates GROUP BY GROUP BY divides rows into groups, and aggregate functions compute values for each group. Every selected column must either appear in GROUP BY or be used in an aggregate. HAVING HAVING filters groups after aggregation (unlike WHERE which filters rows before grouping). GROUPING SETS, CUBE, ROLLUP PostgreSQL supports advanced grouping for…