SQL - How to count by condition

SQL - How to count by condition #

There’s a bunch of different ways to count by some specified condition.

Here’s one way that makes it a fairly compact query:

SELECT
    --<grouping field> optional
    SUM(CASE WHEN <field>=<condition value> THEN 1 else 0 end) <new name>
    ...
FROM <table>
--GROUP BY <grouping field> optional