File tree 1 file changed +7
-6
lines changed
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -726,19 +726,20 @@ SELECT city, max(temp_lo)
726
726
which gives us one output row per city. Each aggregate result is
727
727
computed over the table rows matching that city.
728
728
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>:
730
731
731
732
<programlisting>
732
- SELECT city, max(temp_lo)
733
+ SELECT city, max(temp_lo), count(*) FILTER (WHERE temp_lo < 30)
733
734
FROM weather
734
735
GROUP BY city
735
736
HAVING max(temp_lo) < 40;
736
737
</programlisting>
737
738
738
739
<screen>
739
- city | max
740
- ---------+-----
741
- Hayward | 37
740
+ city | max | count
741
+ ---------+-----+-------
742
+ Hayward | 37 | 5
742
743
(1 row)
743
744
</screen>
744
745
@@ -748,7 +749,7 @@ SELECT city, max(temp_lo)
748
749
names begin with <quote><literal>S</literal></quote>, we might do:
749
750
750
751
<programlisting>
751
- SELECT city, max(temp_lo)
752
+ SELECT city, max(temp_lo), count(*) FILTER (WHERE temp_lo < 30)
752
753
FROM weather
753
754
WHERE city LIKE 'S%' -- <co id="co.tutorial-agg-like"/>
754
755
GROUP BY city
You can’t perform that action at this time.
0 commit comments