mysql if 、ifnull、is not null 和isnull函数

来源:互联网 发布:剑灵灵族女捏脸数据 编辑:程序博客网 时间:2024/06/08 06:56

一、IF函数
表达式:IF(expr1,expr2,expr3)
满足条件expr1即条件expr1返回true
则expr2否则就是expr3 返回false
作为排序条件使用时 放在order by 后
eg:
1. SELECT IF(1=1,2,3); 则输出2
2.SELECT IF(1=2,2,3);则输出3
select * from test_table order by if(ISNULL(idcard),1,0)
二、IFNULL函数
表达式:IFNULL(expr1,expr2)
如果expr1值为NULL,则输出expr2
如果expr1值不为空则输出expr1本身

eg:
1.SELECT IFNULL(null,”2”);则输出2
2.SELECT IFNULL(3,”2”);则输出3

三、is not null函数
select * from test where name is not null;
四、isnull(expr) 的用法:
如expr 为null,那么isnull() 的返回值为 1,否则返回值为 0。

0 0
原创粉丝点击