[ Pobierz całość w formacie PDF ]
.Using Aggregate FunctionsPostgreSQL User's GuidePrevChapter 12.The Query LanguageNextUsing Aggregate Functions Like most other query languages, PostgreSQL supportsaggregate functions.The current implementation of Postgres aggregate functions have some limitations.Specifically, while there are aggregates to computesuch functions as the count, sum,avg (average), max (maximum) andmin (minimum) over a set of instances, aggregates can onlyappear in the target list of a query and not directly in thequalification (the where clause).As an example,SELECT max(temp_lo) FROM weather;is allowed, whileSELECT city FROM weather WHERE temp_lo = max(temp_lo);is not.However, as is often the case the query can be restated to accomplishthe intended result; here by using a subselect:SELECT city FROM weather WHERE temp_lo = (SELECT max(temp_lo) FROM weather); Aggregates may also have group by clauses:SELECT city, max(temp_lo)FROM weatherGROUP BY city;PrevHomeNextDeletionsUpDisk Storage
[ Pobierz całość w formacie PDF ]