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)
    
  • 相关阅读:
    大型网站--前端性能优化和规范
    大型网站--负载均衡架构
    最具有性价比的语言javascript之二,学习篇
    最具有性价比的语言javascript之介绍篇
    《贴吧合伙人》——百度已经沦落到卖血为生?
    用rust实现高性能的数据压缩工具
    高性能的数据压缩库libzling-20160105
    高性能的数据压缩库libzling-20140324
    高性能的数据压缩库libzling
    简易js模板引擎
  • 原文地址:https://www.cnblogs.com/JuncaiF/p/11162767.html
Copyright © 2011-2022 走看看