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> 

    水果大佬
  • 相关阅读:
    最短路径:HDU2006-一个人的旅行(多个起点,多个终点)
    最短路径(最基础,经典的模板和思想):HDU-2544最短路
    数学算法:poweroj1026-丑数(根据固定倍数得到从小到大的序列)
    动态规划:ZOJ1074-最大和子矩阵 DP(最长子序列的升级版)
    数论:HDU1066-Last non-zero Digit in N!
    容斥原理:HDU-4135Co-prime
    数学算法:求一个数的质因子
    动态规划(入门,滚动数组,记录的都是状态):SWUSTACM-1010 魔兽争霸之最后的反击
    动态规划(入门):各种数字三角形
    动态规划:HDU2571-命运
  • 原文地址:https://www.cnblogs.com/tanshouke/p/12360056.html
Copyright © 2011-2022 走看看