Postgres-XC 1.0.1 Documentation | ||||
---|---|---|---|---|
Prev | Fast Backward | Chapter 2. The SQL Language | Fast Forward | Next |
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.