当前位置:网站首页>mysql函数汇总之条件判断函数
mysql函数汇总之条件判断函数
2022-07-26 08:11:00 【运维家】
条件判断函数也被称为控制流程函数,根据满足的不同条件,执行响应的流程。
mysql中进行条件判断的函数有if、ifunll和case等。
IF(expr,v1,v2)函数
IF(expr,v1,v2):如果表达式expr是TRUE(expr <> 0 and expr <> null),则返回值为V1;否则返回值为V2。
mysql> select if (1>2, 2, 3), if (1<2, 'yes', 'no');
+----------------+-----------------------+
| if (1>2, 2, 3) | if (1<2, 'yes', 'no') |
+----------------+-----------------------+
| 3 | yes |
+----------------+-----------------------+
1 row in set (0.00 sec)
mysql>
小提示:
如果V1或者V2中只有一个明确是
null,则if()函数的结果类型为非null表达式的结果类型。
IFNULL(v1,v2)函数
ifnull(v1,v2):假如V1不为null,则ifnull()的返回值为v1;否则其返回值为v2。
ifnull()的返回值是数字或者字符串,具体情况取决于其所在的语境。
mysql> select ifnull(1, 2), ifnull(null, 'yunweijia'), ifnull(1/0, 'heihei');
+--------------+---------------------------+-----------------------+
| ifnull(1, 2) | ifnull(null, 'yunweijia') | ifnull(1/0, 'heihei') |
+--------------+---------------------------+-----------------------+
| 1 | yunweijia | heihei |
+--------------+---------------------------+-----------------------+
1 row in set (0.00 sec)
mysql>
CASE函数
case expr when v1 then r1 [when v2 then 2]...[else rn+1]end:如果expr值等于某个vn,则返回对应位置then后面的结果;如果与所有值都不相等,则返回else后面的rn+1。
mysql> select case 2 when 1 then 'one' when '2' then 'two' else 'more' end;
+--------------------------------------------------------------+
| case 2 when 1 then 'one' when '2' then 'two' else 'more' end |
+--------------------------------------------------------------+
| two |
+--------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
mysql> select case 5 when 1 then 'one' when '2' then 'two' else 'more' end;
+--------------------------------------------------------------+
| case 5 when 1 then 'one' when '2' then 'two' else 'more' end |
+--------------------------------------------------------------+
| more |
+--------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
小提示:
可以按照
shell中的if语句来理解。一个
case表达式的默认返回值类型是任何返回值的相容集合类型,但具体情况视其所在语境而定。
至此,本文结束。
更多内容请转至VX公众号 “运维家” ,获取最新文章。
------ “运维家” ------
------ “运维家” ------
------ “运维家” ------
linux中断异常,linuxuml建模,linux编译多个源文件,linux怎么更新时间,linux中的分页视频教程,
linux怎么解压gzip,linux解压某个目录,怎么关闭linux网关,linux文件架构图,linux提高权限执行,
linux文件用什么标志,网络安全linux加固,linux中查看邮件,linux修改背景颜色,linux环境下搭建网站。
边栏推荐
- Burp Suite-第九章 如何使用Burp Repeater
- JSP implicit object -- scope
- The first ide overlord in the universe, replaced...
- 2022-07-09 group 5 Gu Xiangquan's learning notes day02
- Now developers are beginning to do testing. Will there be no software testers in the future?
- Add traceid to the project log
- Lnmp+wordpress to quickly build a personal website
- Burp suite Chapter 4 advanced options for SSL and proxy
- Team members participate in 2022 China multimedia conference
- Template summary
猜你喜欢

One click deployment lamp and LNMP architecture

Burp Suite-第一章 Burp Suite 安装和环境配置

The most complete network: detailed explanation of six constraints of MySQL
![[fastjson1.2.24 deserialization vulnerability principle code analysis]](/img/14/8f6a75fe5f06c19eeff9c7204979c3.png)
[fastjson1.2.24 deserialization vulnerability principle code analysis]

Burp Suite-第八章 如何使用Burp Intruder

OSPF总结

线程崩了,为什么不会导致 JVM 崩溃呢?如果是主线程呢?

Spotty music data client_ ID account

Now developers are beginning to do testing. Will there be no software testers in the future?

Lnmp+wordpress to quickly build a personal website
随机推荐
The difference between LinkedList and ArrayList
File parsing (JSON parsing)
Common database commands (special for review)
2022 / 7 / 16 exam summary
我,35岁了。
2022/7/12 exam summary
Excel file reading and writing (creation and parsing)
Burp Suite-第九章 如何使用Burp Repeater
Establishment and use of openstack cloud platform
Summarize the common high-frequency interview questions of the software testing post
JSP implicit object servlet object
No valid host was found when setting up openstack to create an instance There are not enough hosts available. code:500
Use of views
全网最全:Mysql六种约束详解
Why is Google's internal tools not suitable for you?
2022 7/5 exam summary
Burp suite Chapter 4 advanced options for SSL and proxy
AQS implementation principle
The idea of stack simulating queue
Burp suite Chapter 9 how to use burp repeater