下文对mysql ifnull函数的使用进行了详细的叙述,供您参考学习,如果您在mysql ifnull函数使用方面遇到过类似的问题,不妨一看。
mysql ifnull(expr1,expr2)
如果expr1不是null,ifnull()返回expr1,否则它返回expr2。ifnull()返回一个数字或字符串值,取决于它被使用的上下文环境。
mysql> select ifnull(1,0);
-> 1
mysql> select ifnull(0,10);
-> 0
mysql> select ifnull(1/0,10);
-> 10
mysql> select ifnull(1/0,yes);
-> yes
if(expr1,expr2,expr3)
如果expr1是true(expr10且expr1null),那么if()返回expr2,否则它返回expr3。if()返回一个数字或字符串值,取决于它被使用的上下文。
mysql> select if(1>2,2,3);
-> 3
mysql> select if(1 -> yes
mysql> select if(strcmp(test,test1),yes,no);
-> no
expr1作为整数值被计算,它意味着如果你正在测试浮点或字符串值,你应该使用一个比较操作来做。
mysql> select if(0.1,1,0);
-> 0
mysql> select if(0.10,1,0);
-> 1
在上面的第一种情况中,if(0.1)返回0,因为0.1被变换到整数值, 导致测试if(0)。这可能不是你期望的。在第二种情况中,比较测试原来的浮点值看它是否是非零,比较的结果被用作一个整数。
case value when [compare-value] then result [when [compare-value] then result ...] [else result] end
case when [condition] then result [when [condition] then result ...] [else result] end
第一个版本返回result,其中value=compare-value。第二个版本中如果第一个条件为真,返回result。如果没有匹配的result值,那么结果在else后的result被返回。如果没有else部分,那么null被返回。
mysql> select case 1 when 1 then one when 2 then two else more end;
-> one
mysql> select case when 1>0 then true else false end;
-> true
mysql> select case binary b when a then 1 when b then 2 end;
-> null
下文对mysql ifnull函数的使用进行了详细的叙述,供您参考学习,如果您在mysql ifnull函数使用方面遇到过类似的问题,不妨一看。
mysql ifnull(expr1,expr2)
如果expr1不是null,ifnull()返回expr1,否则它返回expr2。ifnull()返回一个数字或字符串值,取决于它被使用的上下文环境。
mysql> select ifnull(1,0);
-> 1
mysql> select ifnull(0,10);
-> 0
mysql> select ifnull(1/0,10);
-> 10
mysql> select ifnull(1/0,yes);
-> yes
if(expr1,expr2,expr3)
如果expr1是true(expr10且expr1null),那么if()返回expr2,否则它返回expr3。if()返回一个数字或字符串值,取决于它被使用的上下文。
mysql> select if(1>2,2,3);
-> 3
mysql> select if(1 -> yes
mysql> select if(strcmp(test,test1),yes,no);
-> no
expr1作为整数值被计算,它意味着如果你正在测试浮点或字符串值,你应该使用一个比较操作来做。
mysql> select if(0.1,1,0);
-> 0
mysql> select if(0.10,1,0);
-> 1
在上面的第一种情况中,if(0.1)返回0,因为0.1被变换到整数值, 导致测试if(0)。这可能不是你期望的。在第二种情况中,比较测试原来的浮点值看它是否是非零,比较的结果被用作一个整数。
case value when [compare-value] then result [when [compare-value] then result ...] [else result] end
case when [condition] then result [when [condition] then result ...] [else result] end
第一个版本返回result,其中value=compare-value。第二个版本中如果第一个条件为真,返回result。如果没有匹配的result值,那么结果在else后的result被返回。如果没有else部分,那么null被返回。
mysql> select case 1 when 1 then one when 2 then two else more end;
-> one
mysql> select case when 1>0 then true else false end;
-> true
mysql> select case binary b when a then 1 when b then 2 end;
-> null