找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
查询==select

select * from 表名;==》查询全表数据(*代表所有)
select 字段 from 表名;==》查询单个字段
select 字段1,字段2, from 表名;==》查询多个字段
select * from 表名 where 字段=值;(where后面接满足的条件)==》查询满足某个条件的所有数据
select * from 表名 where 字段 !=value;(!=代表不等于,也可用"<>"代表)==》查询不满足某个条件的所有数据
select * from 表名 where 条件1 and 条件2;(and关键字左右的2个条件必须同时满足)==》查询同时满足多个条件数据
select * from 表名 where 条件1 or 条件2;(or关键字左右的两个条件至少满足一个)==》查询满足至少一个条件的数据

select * from 表名 where 字段 between a and b(between...and...指定一个范围)==》查询一个条件范围内的数据
select * from 表名 where 字段 in(值1,值2,值3)==》查询字段满足在指定的集合中的数据
select * from 表名 where 字段 not in(值1,值2,值3)==》查询字段不满足在指定集合中的数据
select * from 表名 where 字段 is null ==》查询字段为空的数据
select * from 表名 where 字段 is not null ==》查询字段不为空的数据
0不等于null  null的前面只能is null,is not null
select * from 表名 where 字段 like "%qq%" ==》查询某个字段值有包含a的所有数据
select * from 表名 where 字段 like "a%"==》查询某个字段以qq开头的数据
select * from 表名 where 字段 like "%a"==》查询某个字段以a结尾的数据
select * from 表名 字段 limit m,n(m指下标,n指查询的行数,下表为m的开始的n条数据)==》查询限定的数量的数据,(比如查询3-6行m=3-1=2 ;n=6-2=4)

排序:
从小到大:升序 select * from 表名 order by 字段 asc==》查询的数据根据某个字段从小到大排序
从大到小:降序 select * from 表名 order by 字段 desc==》查询的数据根据某个字段从大到小排序
select * from 表名 group by 字段==》查询的数据根据某个字段分组
select * from 表名 group by 字段 having 条件==》查询的数据根据某个字段进行分组在条件过滤

常用的聚合函数:
count()--统计              select count(*)from 表名==》统计查询数据的数量
sum()--求和                select sun(字段) from 表名==》查询某个字段求和
avg()--求平均值          select avg(字段) from 表名==》查询某个字段进行平均值
max()--最大值             select max(字段) from 表名==》查询某个字段最大值
min()--最小值              select min(字段) from 表名==》查询某个字段最小值
distinct()--去重            select distinct(字段) from 表名==》对某个字段进行去重


备份表:
create table 表1 like 表2==》备份表,创建一个表与某个表相同(表1为新表,表2为想备份的表)
insert into 表1 select * from 表2==》往表1里面插入表2的所有数据
insert into 表1(字段1,字段2)select 字段1,字段2 from 表2==》把表2里的某些字段插入到一个新表中
注意点:1:插入的表必须存在    2:插入的表是新表,没有数据

备份库:
mysqldump -uroot -p123456 dcs9>/dcs9/dcs9.sql ==》把dcs9这个库备份放到dsc9目录下的dcs9.sql文件中
mysqldump -uroot -p123456 dcs9_bak注意:dcs9_bak要先存在,不然会找不到库







分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册