Skip to content

Commit d55fdfb

Browse files
committed
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
1 parent 4e3eb6d commit d55fdfb

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

doc/src/sgml/query.sgml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -728,19 +728,20 @@ SELECT city, max(temp_lo)
728728
which gives us one output row per city. Each aggregate result is
729729
computed over the table rows matching that city.
730730
We can filter these grouped
731-
rows using <literal>HAVING</literal>:
731+
rows using <literal>HAVING</literal> and the output count using
732+
<literal>FILTER</literal>:
732733

733734
<programlisting>
734-
SELECT city, max(temp_lo)
735+
SELECT city, max(temp_lo), count(*) FILTER (WHERE temp_lo &lt; 30)
735736
FROM weather
736737
GROUP BY city
737738
HAVING max(temp_lo) &lt; 40;
738739
</programlisting>
739740

740741
<screen>
741-
city | max
742-
---------+-----
743-
Hayward | 37
742+
city | max | count
743+
---------+-----+-------
744+
Hayward | 37 | 5
744745
(1 row)
745746
</screen>
746747

@@ -750,7 +751,7 @@ SELECT city, max(temp_lo)
750751
names begin with <quote><literal>S</literal></quote>, we might do:
751752

752753
<programlisting>
753-
SELECT city, max(temp_lo)
754+
SELECT city, max(temp_lo), count(*) FILTER (WHERE temp_lo &lt; 30)
754755
FROM weather
755756
WHERE city LIKE 'S%' -- <co id="co.tutorial-agg-like"/>
756757
GROUP BY city

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy