Excellent! The same kind of report can also be created using
SUM() instead of
COUNT(). Take a look:
WHEN ShipCountry = N'USA' OR ShipCountry = N'Canada' THEN 1
END) AS FreeShipping,
WHEN ShipCountry != N'USA' AND ShipCountry != N'Canada' THEN 1
END) AS PaidShipping
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.