The WHEN clause in SQL is used to specify conditions in a CASE expression and return the corresponding output. The syntax is as follows: CASE WHEN condition THEN result END. When the condition is TRUE, the corresponding result is returned.
WHEN usage in SQL
What is the WHEN clause?
The WHEN clause is used to specify conditions in a CASE expression and return the appropriate output.
Grammar:
<code>CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 ... ELSE result_default -- 可选 END</code>
How to use the WHEN clause?
Example:
<code>-- 根据成绩计算等级 CASE WHEN grade >= 90 THEN '优等' WHEN grade >= 80 THEN '良好' WHEN grade >= 70 THEN '中等' ELSE '不及格' END</code>
Note:
The above is the detailed content of When usage in sql. For more information, please follow other related articles on the PHP Chinese website!