(四)mysql -- 常用函数

慢慢补充~

 

  •  将varchar转换成int

    例如:select * from tb_1 order by cast(sport_sum as unsigned integer) desc  # 适用‘100’,字母不适用

         select * from tb_1 order by cast(sport_sum as signed integer) desc

  • 将date转换成char

    例如:CONVERT(a.create_time, CHAR) 

  • 截取小数点后几位(不四舍五入,直接截断)

    例如:select TRUNCATE(2.31468, 4)  返回 2.3146  # 仅针对浮点数,字符串不适用

  • 截取小数点后几位(四舍五入)

    例如:select ROUND(2.31468, 4)  返回2.3147

  • 向上取整

    例如: select ceiling(2.317)      3
        select ceiling(2.917)      3

  • 向下取整

    例如: select floor(2.317)        2
           select floor(2.917)        2

 

 

获取字符串长度:

length获取字符串的占位长度

  char_length获取字符串的实际长度

ps:使用utf8编码时,一个汉字或中文字符是3字节,一个数字或字母是1字节

 

posted @ 2019-02-26 17:13  小虫虫大虫虫  阅读(129)  评论(0编辑  收藏  举报