amazon-redshiftHow do I use the CASE WHEN statement in Amazon Redshift?
The CASE WHEN statement is used to evaluate a set of conditions and return a result. It is similar to an IF-THEN-ELSE statement. In Amazon Redshift, the CASE WHEN statement is used to evaluate a set of conditions and return a result based on the conditions that are met.
For example, the following code will return either 'Pass' or 'Fail' depending on the value of the 'grade' column:
SELECT CASE WHEN grade >= 50 THEN 'Pass' ELSE 'Fail' END AS result
FROM table_name
The code consists of the following parts:
- The
CASE
keyword, which starts the statement. - The
WHEN
keyword, which is followed by a condition. - The
THEN
keyword, which is followed by the result if the condition is met. - The
ELSE
keyword, which is followed by the result if the condition is not met. - The
END
keyword, which ends the statement.
For more information about the CASE WHEN statement in Amazon Redshift, please refer to the documentation.
More of Amazon Redshift
- How can I monitor Amazon RDS using Zabbix?
- How do I use the Amazon Redshift YEAR function?
- How can I handle divide by zero errors when using Amazon Redshift?
- How do I use Amazon Redshift with YouTube?
- How can I use Amazon Redshift UNION to combine data from multiple tables?
- How do I use Amazon Redshift window functions?
- How do I set up Amazon RDS with read replicas?
- How do I set up Amazon RDS with Multi-AZ for high availability?
- How can I use Amazon Redshift to store and process unstructured data?
- How can I calculate the serverless pricing for Amazon Redshift?
See more codes...