From the course: SQL for Non-Programmers

Unlock the full course today

Join today to access over 23,100 courses taught by industry experts.

Beyond basic CASE statements

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…

Contents