zoukankan      html  css  js  c++  java
  • mysql常用函数

    常用函数

    字符串函数

    1.concat (concatenate)拼接

    mysql> select concat ('a','b'),concat ('aa',null);
    +------------------+--------------------+
    | concat ('a','b') | concat ('aa',null) |
    +------------------+--------------------+
    | ab               | NULL               |
    +------------------+--------------------+
    1 row in set (0.00 sec)
    

    2.大小写

    mysql> select lower('BEIjing2008'),upper('BEIjing2008');
    +----------------------+----------------------+
    | lower('BEIjing2008') | upper('BEIjing2008') |
    +----------------------+----------------------+
    | beijing2008          | BEIJING2008          |
    +----------------------+----------------------+
    1 row in set (0.00 sec)
    

    3.去除空格

    mysql> select ltrim('  |beijing'),rtrim('beijing|  ');
    +---------------------+---------------------+
    | ltrim('  |beijing') | rtrim('beijing|  ') |
    +---------------------+---------------------+
    | |beijing            | beijing|            |
    +---------------------+---------------------+
    1 row in set (0.00 sec)
    mysql> select trim('    |beijing| ');
    +------------------------+
    | trim('    |beijing| ') |
    +------------------------+
    | |beijing|              |
    +------------------------+
    1 row in set (0.00 sec)
    

    数值函数

    函数 功能
    ABS(x) 绝对值
    CEIL(x) '天花板',向上取整数,比x大的整数
    FLOOR(x) '地板',向下取整,比x小的最大整数
    MOD(x,y) 返回x/y的模
    RAND (1,0)之间的随机小数
    ROUND(x,y) x四舍五入,保留y位小数
    TRUNCATE(x,y) x的小数截断为y位置
    mysql> select abs(-0.18),abs(11);
    +------------+---------+
    | abs(-0.18) | abs(11) |
    +------------+---------+
    |       0.18 |      11 |
    +------------+---------+
    1 row in set (0.00 sec)
    
    mysql> select ceil(0.18),floor(0.18);
    +------------+-------------+
    | ceil(0.18) | floor(0.18) |
    +------------+-------------+
    |          1 |           0 |
    +------------+-------------+
    1 row in set (0.00 sec)
    
    mysql> select mod(5,9),mod(9,5);
    +----------+----------+
    | mod(5,9) | mod(9,5) |
    +----------+----------+
    |        5 |        4 |
    +----------+----------+
    1 row in set (0.01 sec)
    
    mysql> select rand(),100*rand();
    +---------------------+-------------------+
    | rand()              | 100*rand()        |
    +---------------------+-------------------+
    | 0.14313656943211012 | 56.13369816554123 |
    +---------------------+-------------------+
    1 row in set (0.00 sec)
    
    mysql> select round(1.123456,5),truncate(1.123456,5);
    +-------------------+----------------------+
    | round(1.123456,5) | truncate(1.123456,5) |
    +-------------------+----------------------+
    |           1.12346 |              1.12345 |
    +-------------------+----------------------+
    1 row in set (0.00 sec)
    
    

    时间函数

    函数 功能
    CURDATE() 年月日
    CURTIME() 时分秒
    NOW() 年月日时分秒
    mysql> select curdate(),curtime(),now();
    +------------+-----------+---------------------+
    | curdate()  | curtime() | now()               |
    +------------+-----------+---------------------+
    | 2019-07-10 | 03:11:37  | 2019-07-10 03:11:37 |
    +------------+-----------+---------------------+
    1 row in set (0.00 sec)
    

    流程函数

    函数 功能
    if(value,t,f) value为真为t
    ifnull(v1,v2) v1不为空返回v1,否则返回v2
    
    mysql> select if(true,1,2),if(false,1,2),ifnull(null,1);
    +--------------+---------------+----------------+
    | if(true,1,2) | if(false,1,2) | ifnull(null,1) |
    +--------------+---------------+----------------+
    |            1 |             2 |              1 |
    +--------------+---------------+----------------+
    1 row in set (0.00 sec)
    
  • 相关阅读:
    1月19号 UIImageView
    1月18号 UILabel 加上导入.tff格式的字体
    1月18号 UIButton
    2016年 1月15号 cocoapods的导入
    1月12号 UIView
    12月30号 iOS程序准备
    12月29号 计算器(包含混合运算)
    2016.01.13 代理设计模式
    2016.01.04 视图控制器UIViewController
    2015.12.31 iOS程序准备(developer.apple.com)
  • 原文地址:https://www.cnblogs.com/JuncaiF/p/11162767.html
Copyright © 2011-2022 走看看