Interesting things I've learned: The FILTER clause in SQL
( H/T @winand.at )
In SQL, if you wanted to perform two or more aggregations with different filters, you might be able to use the FILTER clause.
SELECTcount(*) as user_count,count(*) filter (where verified = true) as verified_user_countFROM users;
is the equivalent of:
SELECTcount(*) as user_count,sum(case when verified = true then 1 else 0 end) as verified_user_countFROM users;
except that a) it reads more naturally, and b) you don't need to write a complicated case expression.
FILTER is supported in Postgres 9.4 and above, and in sqlite. It is unfortunately not widely supported in other databases.