From: Bruce Momjian Date: Thu, 1 Sep 2022 02:19:05 +0000 (-0400) Subject: doc: use FILTER in aggregate example X-Git-Tag: REL_10_23~46 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=de73544bb46dc141c870b92ca103c119126c7f91;p=postgresql.git doc: use FILTER in aggregate example Reported-by: michal.palenik@freemap.sk Discussion: https://postgr.es/m/163499710897.684.7420075366995883688@wrigleys.postgresql.org Backpatch-through: 10 --- diff --git a/doc/src/sgml/query.sgml b/doc/src/sgml/query.sgml index 10a1e64ab45..929244e8db6 100644 --- a/doc/src/sgml/query.sgml +++ b/doc/src/sgml/query.sgml @@ -728,19 +728,20 @@ SELECT city, max(temp_lo) which gives us one output row per city. Each aggregate result is computed over the table rows matching that city. We can filter these grouped - rows using HAVING: + rows using HAVING and the output count using + FILTER: -SELECT city, max(temp_lo) +SELECT city, max(temp_lo), count(*) FILTER (WHERE temp_lo < 30) FROM weather GROUP BY city HAVING max(temp_lo) < 40; - city | max ----------+----- - Hayward | 37 + city | max | count +---------+-----+------- + Hayward | 37 | 5 (1 row) @@ -750,7 +751,7 @@ SELECT city, max(temp_lo) names begin with S, we might do: -SELECT city, max(temp_lo) +SELECT city, max(temp_lo), count(*) FILTER (WHERE temp_lo < 30) FROM weather WHERE city LIKE 'S%' -- GROUP BY city