MySQL 都是小的公式

Select 列名 别称,列名 别称 from 表名
Select * from 表名 where 条件 Select * from 表名 where job = ‘CLERK’
Select * from 表名 where job = ‘clerk’
不区分大小写
Select * from 表名 where binary job = ‘clerk’ 区分大小写
Select * from 表名 where 列名 is not null
Select * from 表名 where 条件1 and 条件2
Select * from 表名 where 条件1 && 条件2
Select * from 表名 where 条件1 or 条件2
Select * from 表名 where 条件1 || 条件2
Select distinct 列名 from 表名 列中的数据不重复
Select * from 表名 order by 列名 asc
Select * from 表名 order by 列名 desc 升序排序(默认升序)
降序排序
Select * from 表名 where 条件 order by 列名 [asc/desc]
= 与where一起使用时,是关系运算符
= 与 set 一起使用时,是赋值运算符

MySQL中的函数
数值型函数
Select 3+5
Select ‘3’+5 --自动类型转换 字符转数字
Select 3-5
Select 3*5
Select 3/5 --非整除
Select 3 div 5 – 整除
Select 5%4 --余数
Select mod(5,4) --mod叫函数
Select abs(2),abs(-2),abs(0) --绝对值
Select ceiling(1.0001),ceil(-9.9999)
Select foor(1.999),floor(-9.0001)
Select round(1.4),round(1.5) – 四舍五入
Select PI()
Select pow(2,3),power(2,3) — 2的3次方
Select rand() – [0,1]
Select sqrt(4) --开平方

字符型函数
Select ascii(‘abc’) 字符串最左侧字符的ascii值
Select bin(5) 5的二进制数
Select char_length(列名) from 表名
Select char_length(‘helloworld’) 表中的列,列中值得长度
字符串的长度
Select concat(‘hello’,’world’,’java’) 字符串连接
Select insert(‘helloworld’,6,4,’javaSE’) 字符串,第几个,换几个,换成什么
Select left(‘helloworld’,5)
Select right(‘helloworld’,5)
Select upper(‘helloworld’)
Select lower(‘HELLO’)
Select ltrim(‘ hello world ’)
Select rtrim(‘ hello world ’)
Select length(rtrim(‘ hello world ’))
Select substring(‘helloworld’,6,3)
Select reverse(‘helloworld’)

日期型函数
Select curdate() – 年月日 2019-06-27
Select curdate() – 20190627
Select curtime() --时分秒
Select now() --年月日,时分秒
Select sysdate()
Select adddate(now(),interval 2 day)
–返回的是在指定的day,year,month加或减
Select adddate(now(),interval -2 day)
Select adddate(now(),interval -2 year)
Select adddate(now(),interval -2 month)
Select date(now()) --年月日
Select time(now()) --时分秒
Select datediff(curdate(),’2008-08-08’)
–两个星期之间的天数差
Select dayofweek(now()) --一周的第几天
Select dayofyear(now()) --一年的第几天
Select dayofmonth(now()) --一月的第几天
Select dayname(now()) --星期几

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值