You want a notional amount, something like this:
sum(case when cancelled = 'false' then 1 else 0 end)
Reason for using sum() . sum() processes the records and adds a value, either 0 or 1 for each record. The value depends on the value cancelled . If false, then sum() incremented by 1 - counts the number of such values.
You can do something similar with count() , for example:
count(case when cancelled = 'false' then cancelled end)
The trick is that count() counts the number of non-null values. The then clause can be anything that is not NULL - cancelled , constant 1 or some other field. Without else, any other value is NULL and not taken into account.
I always preferred the version of sum() over the version of count() , because I think it is more explicit. In other dialects of SQL, you can sometimes shorten it to:
sum(cancelled = 'false')
which, once you get used to it, makes a lot of sense.
source share