zoukankan      html  css  js  c++  java
  • 常用函数:流程函数


    流程函数

    一、MySQL流程函数

    语法:

    case when [value] then [result] ....else[default] end

    1.1 if(expr,v1,v2)

    mysql> select if(1<2,'yes','no'),if(1>2,'yes','no'),if(strcmp('tansk','tanshouke'),'yes','no');
    +--------------------+--------------------+--------------------------------------------+
    | if(1<2,'yes','no') | if(1>2,'yes','no') | if(strcmp('tansk','tanshouke'),'yes','no') |
    +--------------------+--------------------+--------------------------------------------+
    | yes                | no                 | yes                                        |
    +--------------------+--------------------+--------------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> select strcmp('tansk','tanshouke');
    +-----------------------------+
    | strcmp('tansk','tanshouke') |
    +-----------------------------+
    |                           1 |
    +-----------------------------+
    1 row in set (0.00 sec)
    
    mysql> 

    1.2 case

    mysql> select case 1 when 1 then 'one' when 2 then 'two' else 'other' end;
    +-------------------------------------------------------------+
    | case 1 when 1 then 'one' when 2 then 'two' else 'other' end |
    +-------------------------------------------------------------+
    | one                                                         |
    +-------------------------------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> select case 2 when 1 then 'one' when 2 then 'two' else 'other' end; 
    +-------------------------------------------------------------+
    | case 2 when 1 then 'one' when 2 then 'two' else 'other' end |
    +-------------------------------------------------------------+
    | two                                                         |
    +-------------------------------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> select case 3 when 1 then 'one' when 2 then 'two' else 'other' end; 
    +-------------------------------------------------------------+
    | case 3 when 1 then 'one' when 2 then 'two' else 'other' end |
    +-------------------------------------------------------------+
    | other                                                       |
    +-------------------------------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> 

    1.3 case when

    mysql> select case when 2>1 then 'ture' else 'false' end;
    +--------------------------------------------+
    | case when 2>1 then 'ture' else 'false' end |
    +--------------------------------------------+
    | ture                                       |
    +--------------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> 

    1.4 ifnnull ()

    mysql> select ifnull(null,2),ifnull(1,2),ifnull(0/1,2),ifnull(1/0,2);
    +----------------+-------------+---------------+---------------+
    | ifnull(null,2) | ifnull(1,2) | ifnull(0/1,2) | ifnull(1/0,2) |
    +----------------+-------------+---------------+---------------+
    |              2 |           1 |        0.0000 |        2.0000 |
    +----------------+-------------+---------------+---------------+
    1 row in set, 1 warning (0.00 sec)
    
    mysql> 

    水果大佬
  • 相关阅读:
    UVA 11525 好大好大的排列(线段树)
    UVA 11525 好大好大的排列(线段树)
    UVALive 4108城市天际线,混杂着递归与非递归的线段树
    UVALive 4108城市天际线,混杂着递归与非递归的线段树
    zencart搜索结果页面静态化 advanced_search_result
    .htaccess 一段神奇的跳转代码
    清除zencart分类页多页后面的&disp_order &sort字符串的方法
    zencart只有购买过此产品的客户才能评价产品
    mysql自增字段AUTO_INCREMENT重排或归零
    mysql语句修改zencart产品原价为特价的倍数
  • 原文地址:https://www.cnblogs.com/tanshouke/p/12360056.html
Copyright © 2011-2022 走看看