FILTER
Example
Section titled “Example”SELECT COUNT(*) FILTER (WHERE age > 18) AS "number_of_adults", COUNT(*) FILTER (WHERE age <= 18) AS "number_of_children"FROM people;Output
Section titled “Output” number_of_adults | number_of_children------------------+-------------------- 25 | 10Explanation
Section titled “Explanation”The example code counts the number of adults (individuals older than 18 years) and children (individuals 18 years or younger) in the table named people. The FILTER clause specifies the condition based on which the rows are counted.