mysql IF ELSE
时间: 2023-10-23 08:45:42 浏览: 100
mysql if语句的使用,10多年工作总结
The IF ELSE statement in MySQL is used to execute a certain block of code based on a certain condition. It has the following syntax:
IF condition THEN
statements;
ELSE
statements;
END IF;
Here, "condition" is the expression that is evaluated, and "statements" are the actions that are executed based on the result of the evaluation.
For example, consider the following scenario where we want to check if a student has passed or failed an exam based on their score:
IF score >= 50 THEN
SELECT 'Pass';
ELSE
SELECT 'Fail';
END IF;
Here, if the score is greater than or equal to 50, the message "Pass" is displayed; otherwise, the message "Fail" is displayed.
阅读全文