Mysql之数据操作

数据的增删改查:

增:

insert into 表名 values();

删:

物理删除:

delete from 表名 where 条件;

逻辑删除;

改:

update 表名 set 列1=值1,列2=值2... where 条件 ;

查:

全查:

select * from 数据表名;

指定条件查:

select * from 表名 where 条件;

查询列:

select 列1,列2 from 表名;

distinct 去重 select distinct 列名 from 表名;

select * from 表名 as 别名;

条件查询:

select 字段名/* from 表名 where 判断条件;

and or not ...正常用

(内容) 括号内的东西优先级高

__% 至少两位

like 内容 模糊查询

rlike 正则表达式 模糊查询

范围查询:

in() 范围查询 在---范围内

between...and... 在连续的范围内

is null /in not null 空判断

排序:

order by 字段

asc 升序

desc 降序

聚合函数:

select 聚合函数(*) from 表名 where 条件;

count 总数

max 最大值

min 最小值

avg 平均值

round 四舍五入

不能在where中使用

分组:

select 列名(唯一) from 表名 group by 列名;

常和聚合函数一起用 如有条件,条件还是放到表名后面

group_concat(name) 显示分组内的名字

having 对分组进行条件判断

where having区别:

1.位置不同

2.having针对结果 where针对条件

分页:

limit start(起始的下标), count(数据个数) 放到sql语句最后

规律:limit(第n页-1)*每页个数,每页个数

连接查询:

inner join 内连接 取交集 取两个表中都有的数据 on 条件

left join 左连接

评论

暂无评论