mysql之常用函数

mysql之常用函数

  • mysql函数的介绍
  • 聚集函数
    • avg --- select avg(xxx) as "xxx" from schema.table where xxx='xxx'; # 平均值
    • count --- select count (*) as "xxx" from schema.table where xxx='xxx'; # 统计个数
    • max --- select max(xxx) as "xxx" from schema.table where xxx='xxx'; # 最大值
    • min --- select min(xxx) as "xxx" from schema.table where xxx='xxx'; # 最小值
    • sum --- select sum(xxx) as "xxx" from schema.table where xxx='xxx'; # 求和
    • distinct --- select count (distinct  xxx) as "xxx" from schema.table where xxx='xxx'; # 在计算过程中会有重复值出现的话,distinct会将数据去重
  • 用于处理字符串的函数
    • 合并字符串函数:concat(str1,str2,str3…) # 合并字符串直接拼接
    • 合并字符串函数:concat_ws(str1,str2,str3…) # 合并字符串带分隔符
    • 比较字符串大小函数:strcmp(str1,str2) #比较两个字符串的大小。左大于右时返回1,左等于右时返回0,,左小于于右时返回-1,
    • 获取字符串字节数函数:length(str)
    • 获取字符串字符数函数:char_length(str)
    • 字母大小写转换函数:大写:upper(x),ucase(x);小写lower(x),lcase(x)
    • 字符串查找函数
    • 获取指定位置的子串
    • 字符串去空函数
    • 字符串替换函数:
  • 用于处理数值的函数
    • 绝对值函数:abs(x)
    • 向上取整函数:ceil(x)
    • 向下取整函数:floor(x)
    • 取模函数:mod(x,y)
    • 随机数函数:rand()
    • 四舍五入函数:round(x,y)
    • 数值截取函数:truncate(x,y)
  • 用于处理时间日期的函数
    • 获取当前日期:curdate(),current_date()
    • 获取当前时间:curtime(),current_time()
    • 获取当前日期时间:now()
    • 从日期中选择出月份数:month(date),monthname(date)
    • 从日期中选择出周数:week(date)
    • 从日期中选择出周数:year(date)
    • 从时间中选择出小时数:hour(time)
    • 从时间中选择出分钟数:minute(time)
    • 从时间中选择出今天是周几:weekday(date),dayname(date)
    •  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值