Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfede154

Browse files
committed
doc: use FILTER in aggregate example
Reported-by: michal.palenik@freemap.skDiscussion:https://postgr.es/m/163499710897.684.7420075366995883688@wrigleys.postgresql.orgBackpatch-through: 10
1 parentfbd597e commitfede154

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
@@ -726,19 +726,20 @@ SELECT city, max(temp_lo)
726726
which gives us one output row per city. Each aggregate result is
727727
computed over the table rows matching that city.
728728
We can filter these grouped
729-
rows using <literal>HAVING</literal>:
729+
rows using <literal>HAVING</literal> and the output count using
730+
<literal>FILTER</literal>:
730731

731732
<programlisting>
732-
SELECT city, max(temp_lo)
733+
SELECT city, max(temp_lo), count(*) FILTER (WHERE temp_lo &lt; 30)
733734
FROM weather
734735
GROUP BY city
735736
HAVING max(temp_lo) &lt; 40;
736737
</programlisting>
737738

738739
<screen>
739-
city | max
740-
---------+-----
741-
Hayward | 37
740+
city | max | count
741+
---------+-----+-------
742+
Hayward | 37 | 5
742743
(1 row)
743744
</screen>
744745

@@ -748,7 +749,7 @@ SELECT city, max(temp_lo)
748749
names begin with <quote><literal>S</literal></quote>, we might do:
749750

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp