From the course: SQL for Non-Programmers
Unlock the full course today
Join today to access over 23,400 courses taught by industry experts.
Beyond basic CASE statements - SQL Tutorial
From the course: SQL for Non-Programmers
Beyond basic CASE statements
A CASE statement in SQL allows you to have more flexibility over your data, creating new categories of data depending on whether certain conditions are met. We saw how powerful CASE statements can be when we created teams out of our employee data to report on our Two Trees Olive Oil business in Florida. If we circle back to that original query in SLS. We were previously asked to retrieve total sales data for team one and team two in Florida. If we execute our previous query. The output looks like this, with team two slightly ahead of team one, each totaling over 65,000 in sales. But what happens if we remove the Florida filter by deleting the WHERE clause? Check out the results. We've now got a new top row of data, with the employee team labeled as NULL and 1.4 million in sales. Since we removed the Florida filter, this NULL represents all of the other employees and is labeled NULL because we didn't give this group a name. All of the employees that did not meet the team one or the…
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)
Categorize data with CASE8m 51s
-
(Locked)
Beyond basic CASE statements7m 9s
-
(Locked)
Creating Calculated Fields7m 33s
-
(Locked)
Matching data with wildcards7m 57s
-
(Locked)
Combining data with UNION6m 57s
-
(Locked)
Challenge: Practice with advanced commands2m 1s
-
(Locked)
Solution: Advanced commands solved6m 10s
-
(Locked)
-