当前位置:网站首页>MySQL-IF-THEN-ELSE语句
MySQL-IF-THEN-ELSE语句
2022-04-21 15:29:00 【m0_67392661】
定义
IF-THEN-ELSE语句通常用在根据不同条件执行不同SQL的场景。
语法
IF condition1 THEN
{...statements to execute when condition1 is TRUE...}
[ ELSEIF condition2 THEN
{...statements to execute when condition2 is TRUE...} ]
[ ELSE
{...statements to execute when both condition1 and condition2 are FALSE...} ]
END IF;
参数
参数
描述
ELSEIF
可选,按顺序执行判断条件,当结果为true时,执行其中的子句
ELSE
可选,当前面的条件都不为true时,执行其中的子句
例子
DELIMITER //
CREATE FUNCTION IncomeLevel ( monthly_value INT )
RETURNS varchar(20)
BEGIN
DECLARE income_level varchar(20);
IF monthly_value <= 4000 THEN
SET income_level = 'Low Income';
ELSEIF monthly_value > 4000 AND monthly_value <= 7000 THEN
SET income_level = 'Avg Income';
ELSE
SET income_level = 'High Income';
END IF;
RETURN income_level;
END; //
DELIMITER ;
版权声明
本文为[m0_67392661]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_67392661/article/details/124320256
边栏推荐
- LeetCode 654:最大二叉树
- MySQL数据库基础操作-----(基础增删查改)
- Ultimate doll 2.0 | observable practice sharing of cloud native PAAS platform
- 什么是电子邮件的格式?企业邮箱地址是什么?
- Elemetn form control --- automatically locate the position of the field when it is submitted without passing the verification field
- [机器学习导论]——第六课——贝叶斯分类器
- 68页智慧管廊项目建设解决方案
- Mysql
- Why is the power 0 of 2 equal to 1?
- [binary search - simple] LCP 28 Procurement scheme
猜你喜欢

浅析浏览器书签的导入和导出

105 page digital twin city information model CIM platform construction technical scheme

Spark / Scala - read rcfile & orcfile

AcWing 1788. Why do cows cross the road (simulation)
![[Unity] error CS0433: The type ‘Task‘ exists in both Unity. Tasks,....](/img/17/3a0b2e52336bc702ff3b38420e9e6a.png)
[Unity] error CS0433: The type ‘Task‘ exists in both Unity. Tasks,....

Openharmony camera user driven framework
![[Unity] error CS0433: The type ‘Task‘ exists in both Unity.Tasks,....](/img/17/3a0b2e52336bc702ff3b38420e9e6a.png)
[Unity] error CS0433: The type ‘Task‘ exists in both Unity.Tasks,....

读书破万“卷”:国民阅读洞察2022

92页集团信息化规划方案企业应用集成解决方案

Reading breaks ten thousand "volumes": National Reading insight 2022
随机推荐
Detailed explanation of basic knowledge of database 5: index and its two engines in mysql, master-slave replication and relational / non relational database
[Unity] error CS0433: The type ‘Task‘ exists in both Unity.Tasks,....
机器学习方法创建可学习的化学语法,构建可合成的单体和聚合物
Deltix Round, Summer 2021 D. Take a Guess(二进制计算常用性质汇总)
AcWing 1854. Promotion count (Analog)
Hanoi tower game and recursion
MySQL8. 0 correct password change posture
[binary search - medium] 1498 Number of subsequences satisfying the condition
Mysql
JDBC和数据库连接池
102页新一代数字化转型信息化总体规划方案
111 page data word transformation solution of Fine Chemical Co., Ltd
[unity note] l2unity shader Foundation
LeetCode 654:最大二叉树
LaTeX常用公式查询
107页企业数字化转型规划设计
注册登录程序1
JUC concurrent learning notes
Acwing 1775 Lost cattle (simulated)
SQL服务器如何设置起始日期查询语句