In the above query, we used SUM() with CASE WHEN instead of COUNT(). The CASE WHEN construction inside the SUM() function is very similar to that inside COUNT(), but you can see that we pass a 1 to 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 SUM() and COUNT() produce identical results in this query.

Exercise

The template presents a solution to the previous exercise. Modify it so that it uses SUM() instead of COUNT().

Stuck? Here's a hint!

You need to change the function and the CASE WHEN instruction inside it.

Need assistance?

Our website uses cookies. By using this website, you agree to their use in accordance with the browser settings.You can modify your browser settings on your own. For more information see our Privacy Policy.