MYSQL 判断函数
来源:互联网 发布:ubuntu切换中文输入法 编辑:程序博客网 时间:2024/06/06 00:33
--流程函数。if ,ifnull ,case 语句!
mysql> create table sal (id int,sal decimal (9,2));
Query OK, 0 rows affected (0.06 sec)mysql> insert into sal values (1,1000),(2,2000),(3,3000),(4,4000),(5,null);
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0
--if(EXP,T,F) EXP 为真则返回T,EXP为假,则返回F
mysql> select * from sal;
+------+---------+
| id | sal |
+------+---------+
| 1 | 1000.00 |
| 2 | 2000.00 |
| 3 | 3000.00 |
| 4 | 4000.00 |
| 5 | NULL |
+------+---------+
5 rows in set (0.00 sec)
mysql> select id, if(sal > 3000,'high','low') from sal;
+------+-----------------------------+
| id | if(sal > 3000,'high','low') |
+------+-----------------------------+
| 1 | low |
| 2 | low |
| 3 | low |
| 4 | high |
| 5 | low |--这里null >3000 为假!
+------+-----------------------------+
5 rows in set (0.01 sec)
--IFNULL(VAL,N)如果val 为null 则返回N
mysql> select id, ifnull(sal,0) from sal;
+------+---------------+
| id | ifnull(sal,0) |
+------+---------------+
| 1 | 1000.00 |
| 2 | 2000.00 |
| 3 | 3000.00 |
| 4 | 4000.00 |
| 5 | 0.00 |
+------+---------------+
5 rows in set (0.01 sec)
--case 语句和oracle的一样了!
mysql> select case when sal<=3000 then 'low' else 'high' end from sal;
+------------------------------------------------+
| case when sal<=3000 then 'low' else 'high' end |
+------------------------------------------------+
| low |
| low |
| low |
| high |
| high |
+------------------------------------------------+
5 rows in set (0.00 sec)
mysql> select id, case sal when 2000 then 'low' when 3000 then 'mid' else 'high' end from sal;
+------+--------------------------------------------------------------------+
| id | case sal when 2000 then 'low' when 3000 then 'mid' else 'high' end |
+------+--------------------------------------------------------------------+
| 1 | high |
| 2 | low |
| 3 | mid |
| 4 | high |
| 5 | high |
+------+--------------------------------------------------------------------+
5 rows in set (0.01 sec)
- MYSQL 判断函数
- MySQL条件判断函数
- MySQL条件判断函数
- mysql 自定义函数之判断
- MySQL 条件判断函数
- MySql 判断汉字、日期、数字的函数
- mysql 统计函数中加判断语句
- MySQL笔记六之 条件判断函数
- MYSQL ifnull 函数 、if判断 、case when、 locate函数
- MySQL(基础篇)之MySQL(系统函数、加密函数和条件判断函数)
- MySQL 学习<五> MySQL函数简介(条件判断函数、系统信息函数、其他常见函数函数)
- mysql null 值的判断 ifnull函数应用
- mysql null 值的判断 ifnull函数应用
- mysql null 值的判断 ifnull函数应用
- mysql null 值的判断 ifnull函数应用
- mysql null 值的判断 ifnull函数应用
- mysql null 值的判断 ifnull函数应用
- replace MYSQL字符替换函数sql语句分享(正则判断)
- MySQL的AUTO_INCREMENT
- Jquery批量判断是否为空,是否为数字
- 各大银行的软件开发中心
- 命令行运行带有package包路径的java程序
- 网页中如何设置在网页地址栏中的小图标(收藏)
- MYSQL 判断函数
- Linux里的防火墙:netfilter简介与Iptables的使用(上)
- GridView动态生成列方法
- 简单归纳一下行业现状
- iptables的详细用法
- bbossgroups 3.3 发布
- 2011阿里巴巴程序设计公开赛 / 1004 Level up
- NSControl的继承图
- ORA-00600: internal error code, arguments: [keltnfy-ldmInit], [46], [1], [], [], [], [], []