Excellent! The same kind of report can also be created using
SUM() instead of
COUNT(). Take a look:
WHEN ship_country = 'USA' OR ship_country = 'Canada' THEN 1
END) AS free_shipping,
WHEN ship_country != 'USA' AND ship_country != 'Canada' THEN 1
END) AS paid_shipping
In the above query, we used
CASE WHEN instead of
CASE WHEN construction inside the
SUM() function is very similar to that inside
COUNT(), but you can see that we pass a
SUM() when the condition is satisfied. This is a bit different from
COUNT(), where we passed in the column name.
Despite their minor differences, both
COUNT() produce identical results in this query.