From the course: MySQL Data Analysis

Unlock this course with a free trial

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

The CASE statement

The CASE statement - MySQL Tutorial

From the course: MySQL Data Analysis

The CASE statement

- [Instructor] Okay, so now we're going to get into some of the slightly more advanced stuff that can make you a really strong analyst. The first one of those is the case statement. So, a case statement allows us to process a series of IF/THEN logical operators in a specific order. The most common thing I use this for is creating different segments or buckets of my data based on some underlying values, and we'll explain that more in a little bit. Here's the syntax. Every case statement begins with CASE and ends with END, and it always has at least one THEN/WHEN pair. So, the THEN/WHEN pair evaluates a set of logic and then specifies an output. Again, we'll get into this in a little more detail, but the thing to know here is every case has CASE, END and at least one THEN/WHEN pair, and could have more. Here's where you set your various logical operators. Here's an example of a case statement I might look at for selecting a movie to watch with my niece. So, we have WHEN category in…

Contents