From the course: SQL for Healthcare Professionals

Unlock this course with a free trial

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

Using a CASE statement for data classification

Using a CASE statement for data classification - SQL Tutorial

From the course: SQL for Healthcare Professionals

Using a CASE statement for data classification

- [Instructor] One of the challenges that you might face as a healthcare analyst is how to classify your data correctly when meeting certain conditions. That's the perfect scenario to apply the CASE statement. If you're familiar with Excel, think about how you do use the If function. They have some similarities. The CASE statement enables the users to use logic to categorize and label data in a meaningful way. Uses the warrants CASE When to specify the condition, Then to specify the output, End to finish the CASE statement and an optional As to give an alias to the new column. For instance, if you want to categorize patients based on their length of stay in the hospital, you can write a query as follows. Select patient ID, days in the hospital, and then we're going to build our CASE statement. I'm going to say CASE, when the days in the hospital are less or equal to three, then those records are going to be considered…

Contents