From the course: Introduction to SQL Using Google BigQuery

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

CASE WHEN statements

CASE WHEN statements

- [Instructor] The CASE WHEN statement is a very useful transformation, also known as a conditional expression. This is how we can implement if-then-else statements in BigQuery. We can also incorporate CASE WHEN statements with a group by clause to deepen our data analysis. Since we've implemented some logic previously to help us identify cat and dog products based off the product name, let's reuse the same logic to assign a new segment column with a value of cat, dog, or other using the CASE WHEN expression. Notice how we can apply exactly the same logic as a WHERE clause using the LIKE operator to apply the fuzzy matching condition for both cat and dog products. You'll also see that we have an ELSE Other in our SQL query. This defines what BigQuery should return if neither the cat or the dog conditions are met. Let's look into this ELSE feature a little bit further. The ELSE expression for the CASE WHEN statement is…

Contents