mysql增删改查

DQL:数据查询语言 select

一、基础查询:

select 字段名 from 表名;

distinct :去重

as :起别名,起别名也可以用空格替代as

二、条件查询:where

< \> \<> \<= \>= \!= \= \between...and

or \and 

in \not in 

is null \is not null

select * from 表名 where 条件;

三、模糊查询:like

'%' 匹配多个字符, '_' 匹配单个字符。

select * from 表名 where (XXX like '%x%');

四、排序:order by 字段名 [desc | asc]

select * from 表名 where 条件 order by 字段名;

五、限制:limit 偏移量 条目数

select * from 表名 limit 偏移量,条目数;

六、聚合函数:sum min max avg count

select sum(字段) from 表名 where 条件;

select count(字段) from 表名 where 条件;

select max(字段) form 表名 where 条件;

七、分组查询:group by 字段名 having 分组后的基础上进行查询

select 字段,聚合函数 from 表名 where 条件 group by 字段 having 子查询

八、子查询:

select * from 表名 where 条件一 and 子查询条件

九、关联查询:

1、左关联:left join ... on

2、右关联:right join ... on

3、自关联:inner join ... on

select * from 表1 left join 表2 on 防止冗余采用等值操作 here 条件

十、系统函数:

1、字符串函数:

	char_length(str):获取字符串的个数
	
	length(str):获取字符串的字节数
	
	concat(s1,s2...):连接s1,s2..为一个字符串
	
	lower(str):将字符串str中所有的字符转换为小写

	upper(str):将字符串str中所有的字符转换为大写

	left(str,x):返回字符串str最左边的x个字符

	right(str,y):返回字符串str最右边的y个字符

	repeat(str,x):返回str中重复出现x次的结果

	replace(str,a,b):将字符串str中的a更换为b

2、时间函数:

	curdate():得到当前日期

	curtime():得到当前时间

	now():得到当前日期和时间

	year(date):得到date的年份

	month(date):得到date的月份

	day(date):得到date的天

	hour(time):得到time的小时

	minute(time):得到time的分钟

	second(time):得到time的秒

	week(date):得到date是一年中的第几周

	date_format(date,fmt):按格式化串fmt返回date的日期字符串
	
	DATE_ADD(date,INTERVAL number unit)

	date_sub():时间的加减

	datediff(date1,date2):时间差

3、属性函数:

	abs(x):求x的绝对值

	cell(x):向上取整

	floor(x):向下取整

	round(x,d):四舍五入,d为保留小数的位数
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值