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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
The CASE statement2m 43s
-
CASE example5m 43s
-
(Locked)
Common CASE operators4m 18s
-
(Locked)
Challenge: The CASE statement39s
-
(Locked)
Solution: The CASE statement3m 47s
-
(Locked)
Pro tip: Pivoting with COUNT and CASE2m 54s
-
(Locked)
COUNT and CASE demo7m 29s
-
(Locked)
Challenge: COUNT and CASE48s
-
(Locked)
Solution: COUNT and CASE3m 15s
-
(Locked)
-
-
-