SQL SELECT case when
SELECT column1, column2,
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
ELSE result3
END AS new_column
FROM your_table;
In this example, column1
and column2
are the columns you want to select from the table your_table
. The CASE WHEN
statement begins with the CASE
keyword followed by multiple WHEN
conditions. If condition1
is true, result1
will be returned for the new column new_column
. If condition2
is true, result2
will be returned. If none of the conditions are met, result3
will be returned.
You can customize the conditions and results based on your specific requirements. The AS
keyword is used to assign an alias to the new column, which is optional.
#SQL #SELECT #CASEWHEN