In SQL, the "CASE" statement is used for conditional logic within SQL queries.
It allows us to perform conditional evaluations and return different results based on specified conditions.
CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 ... [ELSE else_result] END
The CASE keyword initiates the conditional statement.
WHEN is used to specify a condition.
The condition is evaluated, and if it is true, the corresponding result is returned.
If none of the conditions is true, and an ELSE clause is provided, the else_result is returned.
The END keyword marks the end of the CASE statement.
SELECT employee_id, first_name, last_name, salary, CASE WHEN salary > 50000 THEN 'High Salary' WHEN salary > 30000 THEN 'Moderate Salary' ELSE 'Low Salary' END AS salary_category FROM employees;