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

    一、字符函数

    (1)length 获取参数值的字节个数

    select length('haha');  4

    (2)concat 拼接字符串

    select concat('a','b','c'); 'abc'

    (3)upper 、lower 大写、小写

    select upper('abc');

    select lower('ABC');

    (4)substr、substring 同一个函数,简写全写的区别

    select substr('abcdefg', 3); cdefg 索引从1开始

    select substr('abcdefg', 3,6); cdef 

    (5)instr 返回子串第一次出现的索引值

    select instr('abcd', 'cd'); 3

    (6)trim 去除前后空格 或者指定符号

    select trim('a' from 'abcdaaghjaa');  bcdaaghj

    (7)replace 替换

    select replace('aaabbb', 'b', 'c'); aaaccc

    二、数学函数

    (1)round 四舍五入

    select round(1.5); 2

    select round(1,563, 1); 1.6

    (2) ceil 向上取整,大于等于该参数的最小整数

    select ceil(1.2); 2

    (3) floor 向下取整

    (4)truncate 截断

    select truncate(1.6888, 1); 1.6

    (5)mod 取余

    select mod(10,3); 1

    三、日期函数

    (1)now() 返回当前时间,精确到时分秒

    (2)curdate() 返回当前日期,天

    (3)curtime() 返回当前日期的时分秒,不包含天

    (4)year() month() day() 年月日  hour()  时

    (5)str_to_date 将日期格式的字符串转化成时间

    select str_to_date('1999-02-09', '%Y-%c-%d');

    (6)date_formate 将日期转换成字符

    select date_formate(now(), '%y年%m月%d日');

    四、流程控制函数

    1、if 函数 if(条件表达式,结果一,结果二) 类似三元运算符

    select if(10>5, ‘大’, ‘小’);

    2、case 函数 使用一 switch case 效果

    case 判断的字段或条件表达式

    when 常量1 then 要显示的值1或者(语句1;)

    when .....

    else 要显示的值n或者语句n;

    end

    3、case 函数 使用二 类似于多重if

    case

    when 条件1 then 要显示的值1或语句1

    when.....

    else 要显示的值n或语句n

    end

    五、分组函数

    (1)sum 求和,参数类型只支持数字,忽略null值

    (2)avg 求平均,参数类型只支持数字,忽略null值

    (3)max 最大值

    (4)min 最小值

    (5)count 数据行记录数,非空字段个数,空值字段不做计算。

  • 相关阅读:
    linux超级终端minicom的使用方法
    linux常用命令
    chmod 777 修改权限
    linux mount挂载设备(u盘,光盘,iso等 )使用说明
    logcat的调试 比较有用的几个命令
    git分支
    Debug和Release区别
    【Linux】linux常用基本命令
    Git代码仓库的建立流程
    Linux记录-JMX监控Tomcat上传到falcon
  • 原文地址:https://www.cnblogs.com/dongch/p/14226964.html
Copyright © 2011-2022 走看看