11月21日 数据库第二天 常用函数

字符串函数

1、大小写转换                       upper() /lower()

2、字符串截取                      substring(str,n,len) 从n开始 截取len

3、字符串查找                      instr(str,str1)  返回str第一次出现str1个字符 在的位置 (数字表示)

                                             position() ???还有一个忘了

4、字符串拼接                      concat(‘str1’,‘str2’)

5、字符串替换                      replace(str,‘a’ ,‘b’)   将str中a换成b

6、字符换长度                      length(str);

7、字符串补全                      右边补全 rpad(‘str’,n,‘str’)   左补全lpad('str',n,'str')   n是补全长度 str是补全的符号

 

数值函数

1 四舍五入                          round(num,n)    n是取舍的位数  以小数点为坐标右边为正数 左边为负数

2 舍弃                                truncat(m,n)   n是舍弃的位数

3 取余                                mod(num,n)   num/n

4随机数                               rand()   去0-1的随机数

5 取整                                上取整ceiling()   下取整floor() 

 

 

日期函数

1 当前时间                       now() 年月日时分秒 systime()系统时间   年月日时分秒 curdate()年月日  curtime 时分秒

2相差时间                        timediff(t1,t2) 相差时分秒        datediff(t1,t2) 相差天数

3.增加时间                        date_add(t1,interval num type)  num添加数值 type 是类型 year month day ....

   减少时间                        date_sub(t1,interval num type)

4 最后一天                       last_day()  当月的最后一天

5.抽取日期                        year(now())/month(now())..................方式一

                                          extract(year from now())/extract(month from now()) ...........方式二

6.时间格式化                   date_format(now(),'%Y%m%d') 

                                         time_format(now(),'xxxxxxxxx')

控制语句

if(判断,为真,为假)

case  num when 数值 then 结果2

                   when 数值 then 结果2

                  else 结果3 end 

或者

case  when 判断表达式 then 结果1

        when 判断表达式2 then 结果2

          else 结果3 end

 

多行函数(分组函数)           

1 求和                   sum()

2 求平均值             avg()

3求最大最小值          max() min()

4 计数               count()

关键字 分组  order by  字段

           筛选  having  分组函数!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值