• 常用函数:流程函数



    流程函数

    一、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> 

    水果大佬
  • 相关阅读:
    【P2236】彩票(搜索+剪枝)
    【P1714】切蛋糕(单调队列)
    【P1886】滑动窗口(单调队列→线段树→LCT)
    【P3522】TEM(单调队列+DP)
    【P3957】跳房子(单调队列+DP+二分)
    【P1947】笨笨当粉刷匠(DP+前缀和)
    【P2564】生日礼物(单调队列)
    【[NOI2011]智能车比赛】(建图+spfa+坑爹精度)
    diyiti.cpp
    由最小环问题想到的
  • 原文地址:https://www.cnblogs.com/tanshouke/p/12360056.html
Copyright © 2020-2023  润新知