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