Postgres-XC 1.1 Documentation
Prev | Up | Chapter 2. The SQL Language | Next

# 2.7. Aggregate Functions

> Note: The following description applies both to Postgres-XC and PostgreSQL if not described explicitly.

Like most other relational database products, Postgres-XC supports aggregate functions. An aggregate function computes a single result from multiple input rows. For example, there are aggregates to compute the `count`, `sum`, `avg` (average), `max` (maximum) and `min` (minimum) over a set of rows.

As an example, we can find the highest low-temperature reading anywhere with:

    SELECT max(temp_lo) FROM weather;

     max
    -----
      46
    (1 row)

Aggregates are also very useful in combination with `GROUP BY` clauses. For example, we can get the maximum low temperature observed in each city with:

    SELECT city, max(temp_lo)
        FROM weather
        GROUP BY city;

         city      | max
    ---------------+-----
     Hayward       |  37
     San Francisco |  46
    (2 rows)

which gives us one output row per city. Each aggregate result is computed over the table rows matching that city.

Prev | Home | Next
Joins Between Tables | Up | Updates