From the course: SQL Hands-On Practice: Solve Business Problems

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Introduction to CASE

Introduction to CASE

- [Narrator] CASE is the Swiss Army knife of SQL because it's so versatile and has so many different use cases. Because of this, it can really elevate your SQL game when it comes to data cleaning and data wrangling. A CASE statement consists of a collection of conditions and returns values designated by WHEN and THEN. You can think of it as a fancy IF/THEN statement that can have multiple conditions. A CASE statement goes through each condition in order, and after the first condition is met, the CASE statement stops and returns the value after THEN. You can easily recode variables, or bucket them into categories, based on specific conditions. For example, you could recode state names into state codes. Here we have US states, Georgia and Florida, and they're being recoded into state codes, GA and FL. You can also create a binary column of ones and zeros and flag observations based on a condition. Here, we're flagging…

Contents